1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17: 18: 19: 20:
21:
22: class MetaWeblogApi extends XoopsXmlRpcApi
23: {
24: function MetaWeblogApi(&$params, &$response, &$module)
25: {
26: $this->XoopsXmlRpcApi($params, $response, $module);
27: $this->_setXoopsTagMap('storyid', 'postid');
28: $this->_setXoopsTagMap('published', 'dateCreated');
29: $this->_setXoopsTagMap('uid', 'userid');
30:
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 {
148: $xoops_url = \XoopsBaseConfig::get('url');
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 {
190: $xoops_url = \XoopsBaseConfig::get('url');
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 {
242: $xoops_url = \XoopsBaseConfig::get('url');
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: