XOOPS  2.6.0
xoopsapi.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 
22 class XoopsApi extends XoopsXmlRpcApi
23 {
30  {
31  parent::__construct($params, $response, $module);
32  }
33 
37  public function newPost()
38  {
39  if (!$this->_checkUser($this->params[1], $this->params[2])) {
40  $this->response->add(new XoopsXmlRpcFault(104));
41  } else {
42  if (!$fields = $this->_getPostFields(null, $this->params[0])) {
43  $this->response->add(new XoopsXmlRpcFault(106));
44  } else {
45  $missing = array();
46  foreach ($fields as $tag => $detail) {
47  if (!isset($this->params[3][$tag])) {
48  $data = $this->_getTagCdata($this->params[3]['xoops_text'], $tag, true);
49  if (trim($data) == ''){
50  if ($detail['required']) {
51  $missing[] = $tag;
52  }
53  } else {
54  $post[$tag] = $data;
55  }
56  } else {
57  $post[$tag] = $this->params[3][$tag];
58  }
59  }
60  if (count($missing) > 0) {
61  $msg = '';
62  foreach ($missing as $m) {
63  $msg .= '<'.$m.'> ';
64  }
65  $this->response->add(new XoopsXmlRpcFault(109, $msg));
66  } else {
67  // will be removed... don't worry if this looks bad
68  if (!XoopsLoad::loadFile(\XoopsBaseConfig::get('root-path').'/modules/news/class/class.newsstory.php', true)) {
69  $this->response->add(new XoopsXmlRpcFault(103));
70  return;
71  }
72  $story = new NewsStory();
73  $error = false;
74  if (intval($this->params[4]) > 0) {
75  if (!$this->_checkAdmin()) {
76  // non admin users cannot publish
77  $error = true;
78  $this->response->add(new XoopsXmlRpcFault(111));
79  } else {
80  $story->setType('admin');
81  $story->setApproved(true);
82  $story->setPublished(time());
83  }
84  } else {
85  if (!$this->_checkAdmin()) {
86  $story->setType('user');
87  } else {
88  $story->setType('admin');
89  }
90  }
91  if (!$error) {
92  if (isset($post['categories']) && !empty($post['categories'][0])) {
93  $story->setTopicId(intval($post['categories'][0]['categoryId']));
94  } else {
95  $story->setTopicId(1);
96  }
97  $story->setTitle(addslashes(trim($post['title'])));
98  if (isset($post['moretext'])) {
99  $story->setBodytext(addslashes(trim($post['moretext'])));
100  }
101  if (!isset($post['hometext'])) {
102  $story->setHometext(addslashes(trim($this->params[3]['xoops_text'])));
103  } else {
104  $story->setHometext(addslashes(trim($post['hometext'])));
105  }
106  $story->setUid($this->user->getVar('uid'));
107  $story->setHostname($_SERVER['REMOTE_ADDR']);
108  if (!$this->_checkAdmin()) {
109  $story->setNohtml(1);
110  } else {
111  $story->setNohtml(0);
112  }
113  $story->setNosmiley(0);
114  $story->setNotifyPub(1);
115  $story->setTopicalign('R');
116  $ret = $story->store();
117  if (!$ret) {
118  $this->response->add(new XoopsXmlRpcFault(106));
119  } else {
120  $this->response->add(new XoopsXmlRpcString($ret));
121  }
122  }
123  }
124  }
125  }
126  }
127 
128  function editPost()
129  {
130  if (!$this->_checkUser($this->params[1], $this->params[2])) {
131  $this->response->add(new XoopsXmlRpcFault(104));
132  } else {
133  if (!$fields = $this->_getPostFields($this->params[0])) {
134  } else {
135  $missing = array();
136  foreach ($fields as $tag => $detail) {
137  if (!isset($this->params[3][$tag])) {
138  $data = $this->_getTagCdata($this->params[3]['xoops_text'], $tag, true);
139  if (trim($data) == ''){
140  if ($detail['required']) {
141  $missing[] = $tag;
142  }
143  } else {
144  $post[$tag] = $data;
145  }
146  } else {
147  $post[$tag] = $this->params[3][$tag];
148  }
149  }
150  if (count($missing) > 0) {
151  $msg = '';
152  foreach ($missing as $m) {
153  $msg .= '<'.$m.'> ';
154  }
155  $this->response->add(new XoopsXmlRpcFault(109, $msg));
156  } else {
157  // will be removed... don't worry if this looks bad
158  if (!XoopsLoad::loadFile(\XoopsBaseConfig::get('root-path').'/modules/news/class/class.newsstory.php', true)) {
159  $this->response->add(new XoopsXmlRpcFault(103));
160  return;
161  }
162  $story = new NewsStory($this->params[0]);
163  $storyid = $story->storyid();
164  if (empty($storyid)) {
165  $this->response->add(new XoopsXmlRpcFault(106));
166  } elseif (!$this->_checkAdmin()) {
167  $this->response->add(new XoopsXmlRpcFault(111));
168  } else {
169  $story->setTitle(addslashes(trim($post['title'])));
170  if (isset($post['moretext'])) {
171  $story->setBodytext(addslashes(trim($post['moretext'])));
172  }
173  if (!isset($post['hometext'])) {
174  $story->setHometext(addslashes(trim($this->params[3]['xoops_text'])));
175  } else {
176  $story->setHometext(addslashes(trim($post['hometext'])));
177  }
178  if ($this->params[4]) {
179  $story->setApproved(true);
180  $story->setPublished(time());
181  }
182  $story->setTopicalign('R');
183  if (!$story->store()) {
184  $this->response->add(new XoopsXmlRpcFault(106));
185  } else {
186  $this->response->add(new XoopsXmlRpcBoolean(true));
187  }
188  }
189  }
190  }
191  }
192  }
193 
194  function deletePost()
195  {
196  if (!$this->_checkUser($this->params[1], $this->params[2])) {
197  $this->response->add(new XoopsXmlRpcFault(104));
198  } else {
199  if (!$this->_checkAdmin()) {
200  $this->response->add(new XoopsXmlRpcFault(111));
201  } else {
202  // will be removed... don't worry if this looks bad
203  if (!XoopsLoad::loadFile(\XoopsBaseConfig::get('root-path').'/modules/news/class/class.newsstory.php', true)) {
204  $this->response->add(new XoopsXmlRpcFault(103));
205  return;
206  }
207  $story = new NewsStory($this->params[0]);
208  if (!$story->delete()) {
209  $this->response->add(new XoopsXmlRpcFault(106));
210  } else {
211  $this->response->add(new XoopsXmlRpcBoolean(true));
212  }
213  }
214  }
215  }
216 
217  // currently returns the same struct as in metaWeblogApi
218  function getPost($respond=true)
219  {
220  if (!$this->_checkUser($this->params[1], $this->params[2])) {
221  $this->response->add(new XoopsXmlRpcFault(104));
222  } else {
223  // will be removed... don't worry if this looks bad
224  if (!XoopsLoad::loadFile(\XoopsBaseConfig::get('root-path').'/modules/news/class/class.newsstory.php', true)) {
225  $this->response->add(new XoopsXmlRpcFault(103));
226  return;
227  }
228  $story = new NewsStory($this->params[0]);
229  $ret = array('uid' => $story->uid(), 'published' => $story->published(), 'storyid' => $story->storyId(), 'title' => $story->title('Edit'), 'hometext' => $story->hometext('Edit'), 'moretext' => $story->bodytext('Edit'));
230  if (!$respond) {
231  return $ret;
232  } else {
233  if (!$ret) {
234  $this->response->add(new XoopsXmlRpcFault(106));
235  } else {
236  $struct = new XoopsXmlRpcStruct();
237  $content = '';
238  foreach ($ret as $key => $value) {
239  switch($key) {
240  case 'uid':
241  $struct->add('userid', new XoopsXmlRpcString($value));
242  break;
243  case 'published':
244  $struct->add('dateCreated', new XoopsXmlRpcDatetime($value));
245  break;
246  case 'storyid':
247  $struct->add('postid', new XoopsXmlRpcString($value));
248  $struct->add('link', new XoopsXmlRpcString(\XoopsBaseConfig::get('url').'/modules/news/article.php?item_id='.$value));
249  $struct->add('permaLink', new XoopsXmlRpcString(\XoopsBaseConfig::get('url').'/modules/news/article.php?item_id='.$value));
250  break;
251  case 'title':
252  $struct->add('title', new XoopsXmlRpcString($value));
253  break;
254  default :
255  $content .= '<'.$key.'>'.trim($value).'</'.$key.'>';
256  break;
257  }
258  }
259  $struct->add('description', new XoopsXmlRpcString($content));
260  $this->response->add($struct);
261  }
262  }
263  }
264  }
265 
266  function getRecentPosts($respond=true)
267  {
268  if (!$this->_checkUser($this->params[1], $this->params[2])) {
269  $this->response->add(new XoopsXmlRpcFault(104));
270  } else {
271  if (!XoopsLoad::loadFile(\XoopsBaseConfig::get('root-path').'/modules/news/class/class.newsstory.php', true)) {
272  $this->response->add(new XoopsXmlRpcFault(103));
273  return;
274  }
275  if (isset($this->params[4]) && intval($this->params[4]) > 0) {
276  $stories = NewsStory::getAllPublished(intval($this->params[3]), 0, $this->params[4]);
277  } else {
278  $stories = NewsStory::getAllPublished(intval($this->params[3]));
279  }
280  $scount = count($stories);
281  $ret = array();
282  for ($i = 0; $i < $scount; ++$i) {
283  $ret[] = array('uid' => $stories[$i]->uid(), 'published' => $stories[$i]->published(), 'storyid' => $stories[$i]->storyId(), 'title' => $stories[$i]->title('Edit'), 'hometext' => $stories[$i]->hometext('Edit'), 'moretext' => $stories[$i]->bodytext('Edit'));
284  }
285  if (!$respond) {
286  return $ret;
287  } else {
288  if (count($ret) == 0) {
289  $this->response->add(new XoopsXmlRpcFault(106, 'Found 0 Entries'));
290  } else {
291  $arr = new XoopsXmlRpcArray();
292  $count = count($ret);
293  for ($i = 0; $i < $count; ++$i) {
294  $struct = new XoopsXmlRpcStruct();
295  $content = '';
296  foreach($ret[$i] as $key => $value) {
297  switch($key) {
298  case 'uid':
299  $struct->add('userid', new XoopsXmlRpcString($value));
300  break;
301  case 'published':
302  $struct->add('dateCreated', new XoopsXmlRpcDatetime($value));
303  break;
304  case 'storyid':
305  $struct->add('postid', new XoopsXmlRpcString($value));
306  $struct->add('link', new XoopsXmlRpcString(\XoopsBaseConfig::get('url').'/modules/news/article.php?item_id='.$value));
307  $struct->add('permaLink', new XoopsXmlRpcString(\XoopsBaseConfig::get('url').'/modules/news/article.php?item_id='.$value));
308  break;
309  case 'title':
310  $struct->add('title', new XoopsXmlRpcString($value));
311  break;
312  default :
313  $content .= '<'.$key.'>'.trim($value).'</'.$key.'>';
314  break;
315  }
316  }
317  $struct->add('description', new XoopsXmlRpcString($content));
318  $arr->add($struct);
319  unset($struct);
320  }
321  $this->response->add($arr);
322  }
323  }
324  }
325  }
326 
327  function getCategories($respond=true)
328  {
329  global $xoopsDB;
330  if (!$this->_checkUser($this->params[1], $this->params[2])) {
331  $this->response->add(new XoopsXmlRpcFault(104));
332  } else {
333  if (!XoopsLoad::loadFile(\XoopsBaseConfig::get('root-path').'/class/xoopstopic.php', true)) {
334  $this->response->add(new XoopsXmlRpcFault(103));
335  return;
336  }
337  //$this->db = xoopsDB;
338  $xt = new XoopsTopic($xoopsDB->prefix('topics'));
339  $ret = $xt->getTopicsList();
340  if (!$respond) {
341  return $ret;
342  } else {
343  if (count($ret) == 0) {
344  $this->response->add(new XoopsXmlRpcFault(106, 'Found 0 Entries'));
345  } else {
346  $arr = new XoopsXmlRpcArray();
347  foreach ($ret as $topic_id => $topic_vars) {
348  $struct = new XoopsXmlRpcStruct();
349  $struct->add('categoryId', new XoopsXmlRpcString($topic_id));
350  $struct->add('categoryName', new XoopsXmlRpcString($topic_vars['title']));
351  $struct->add('categoryPid', new XoopsXmlRpcString($topic_vars['pid']));
352  $arr->add($struct);
353  unset($struct);
354  }
355  $this->response->add($arr);
356  }
357  }
358  }
359  }
360 }
361 ?>
if(empty($settings['ROOT_PATH'])) elseif(empty($settings['DB_PARAMETERS'])) $error
$i
Definition: dialog.php:68
deletePost()
Definition: xoopsapi.php:194
$_SERVER['REQUEST_URI']
_getTagCdata(&$text, $tag, $remove=true)
Definition: xmlrpcapi.php:139
_getPostFields($post_id=null, $blog_id=null)
Definition: xmlrpcapi.php:97
editPost()
Definition: xoopsapi.php:128
getCategories($respond=true)
Definition: xoopsapi.php:327
getRecentPosts($respond=true)
Definition: xoopsapi.php:266
static get($name)
global $xoopsDB
Definition: common.php:36
_checkUser($username, $password)
Definition: xmlrpcapi.php:64
newPost()
Definition: xoopsapi.php:37
if(!is_object($module)||!$module->getVar('isactive')) $msg
Definition: groupperm.php:38
static loadFile($file, $once=true)
Definition: xoopsload.php:454
__construct(array &$params, XoopsXmlRpcResponse &$response, XoopsModule &$module)
Definition: xoopsapi.php:29
getPost($respond=true)
Definition: xoopsapi.php:218