1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: |
|
11: |
|
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: |
|
19: |
|
20: | defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
|
21: | require_once XOOPS_ROOT_PATH . '/class/xml/rpc/xmlrpcapi.php';
|
22: |
|
23: | |
24: | |
25: |
|
26: | class BloggerApi extends XoopsXmlRpcApi
|
27: | {
|
28: | |
29: | |
30: | |
31: | |
32: |
|
33: | public function __construct(&$params, &$response, &$module)
|
34: | {
|
35: | parent::__construct($params, $response, $module);
|
36: | $this->_setXoopsTagMap('storyid', 'postid');
|
37: | $this->_setXoopsTagMap('published', 'dateCreated');
|
38: | $this->_setXoopsTagMap('uid', 'userid');
|
39: | }
|
40: |
|
41: | public function newPost()
|
42: | {
|
43: | if (!$this->_checkUser($this->params[2], $this->params[3])) {
|
44: | $this->response->add(new XoopsXmlRpcFault(104));
|
45: | } else {
|
46: | if (!$fields =& $this->_getPostFields(null, $this->params[1])) {
|
47: | $this->response->add(new XoopsXmlRpcFault(106));
|
48: | } else {
|
49: | $missing = array();
|
50: | $post = array();
|
51: | foreach ($fields as $tag => $detail) {
|
52: | $maptag = $this->_getXoopsTagMap($tag);
|
53: | $data = $this->_getTagCdata($this->params[4], $maptag, true);
|
54: | if (trim($data) == '') {
|
55: | if ($detail['required']) {
|
56: | $missing[] = $maptag;
|
57: | }
|
58: | } else {
|
59: | $post[$tag] = $data;
|
60: | }
|
61: | }
|
62: | if (count($missing) > 0) {
|
63: | $msg = '';
|
64: | foreach ($missing as $m) {
|
65: | $msg .= '<' . $m . '> ';
|
66: | }
|
67: | $this->response->add(new XoopsXmlRpcFault(109, $msg));
|
68: | } else {
|
69: | $newparams = array();
|
70: |
|
71: | $newparams[0] = $this->params[1];
|
72: | $newparams[1] = $this->params[2];
|
73: | $newparams[2] = $this->params[3];
|
74: | foreach ($post as $key => $value) {
|
75: | $newparams[3][$key] =& $value;
|
76: | unset($value);
|
77: | }
|
78: | $newparams[3]['xoops_text'] = $this->params[4];
|
79: | $newparams[4] = $this->params[5];
|
80: | $xoopsapi =& $this->_getXoopsApi($newparams);
|
81: | $xoopsapi->_setUser($this->user, $this->isadmin);
|
82: | $xoopsapi->newPost();
|
83: | }
|
84: | }
|
85: | }
|
86: | }
|
87: |
|
88: | public function editPost()
|
89: | {
|
90: | if (!$this->_checkUser($this->params[2], $this->params[3])) {
|
91: | $this->response->add(new XoopsXmlRpcFault(104));
|
92: | } else {
|
93: | if (!$fields =& $this->_getPostFields($this->params[1])) {
|
94: | } else {
|
95: | $missing = array();
|
96: | $post = array();
|
97: | foreach ($fields as $tag => $detail) {
|
98: | $data = $this->_getTagCdata($this->params[4], $tag, true);
|
99: | if (trim($data) == '') {
|
100: | if ($detail['required']) {
|
101: | $missing[] = $tag;
|
102: | }
|
103: | } else {
|
104: | $post[$tag] = $data;
|
105: | }
|
106: | }
|
107: | if (count($missing) > 0) {
|
108: | $msg = '';
|
109: | foreach ($missing as $m) {
|
110: | $msg .= '<' . $m . '> ';
|
111: | }
|
112: | $this->response->add(new XoopsXmlRpcFault(109, $msg));
|
113: | } else {
|
114: | $newparams = array();
|
115: |
|
116: | $newparams[0] = $this->params[1];
|
117: | $newparams[1] = $this->params[2];
|
118: | $newparams[2] = $this->params[3];
|
119: | foreach ($post as $key => $value) {
|
120: | $newparams[3][$key] =& $value;
|
121: | unset($value);
|
122: | }
|
123: | $newparams[3]['xoops_text'] = $this->params[4];
|
124: | $newparams[4] = $this->params[5];
|
125: | $xoopsapi =& $this->_getXoopsApi($newparams);
|
126: | $xoopsapi->_setUser($this->user, $this->isadmin);
|
127: | $xoopsapi->editPost();
|
128: | }
|
129: | }
|
130: | }
|
131: | }
|
132: |
|
133: | public function deletePost()
|
134: | {
|
135: | if (!$this->_checkUser($this->params[2], $this->params[3])) {
|
136: | $this->response->add(new XoopsXmlRpcFault(104));
|
137: | } else {
|
138: |
|
139: | array_shift($this->params);
|
140: | $xoopsapi =& $this->_getXoopsApi($this->params);
|
141: | $xoopsapi->_setUser($this->user, $this->isadmin);
|
142: | $xoopsapi->deletePost();
|
143: | }
|
144: | }
|
145: |
|
146: | public function getPost()
|
147: | {
|
148: | if (!$this->_checkUser($this->params[2], $this->params[3])) {
|
149: | $this->response->add(new XoopsXmlRpcFault(104));
|
150: | } else {
|
151: |
|
152: | array_shift($this->params);
|
153: | $xoopsapi =& $this->_getXoopsApi($this->params);
|
154: | $xoopsapi->_setUser($this->user, $this->isadmin);
|
155: | $ret =& $xoopsapi->getPost(false);
|
156: | if (is_array($ret)) {
|
157: | $struct = new XoopsXmlRpcStruct();
|
158: | $content = '';
|
159: | foreach ($ret as $key => $value) {
|
160: | $maptag = $this->_getXoopsTagMap($key);
|
161: | switch ($maptag) {
|
162: | case 'userid':
|
163: | $struct->add('userid', new XoopsXmlRpcString($value));
|
164: | break;
|
165: | case 'dateCreated':
|
166: | $struct->add('dateCreated', new XoopsXmlRpcDatetime($value));
|
167: | break;
|
168: | case 'postid':
|
169: | $struct->add('postid', new XoopsXmlRpcString($value));
|
170: | break;
|
171: | default :
|
172: | $content .= '<' . $key . '>' . trim($value) . '</' . $key . '>';
|
173: | break;
|
174: | }
|
175: | }
|
176: | $struct->add('content', new XoopsXmlRpcString($content));
|
177: | $this->response->add($struct);
|
178: | } else {
|
179: | $this->response->add(new XoopsXmlRpcFault(106));
|
180: | }
|
181: | }
|
182: | }
|
183: |
|
184: | public function getRecentPosts()
|
185: | {
|
186: | if (!$this->_checkUser($this->params[2], $this->params[3])) {
|
187: | $this->response->add(new XoopsXmlRpcFault(104));
|
188: | } else {
|
189: |
|
190: | array_shift($this->params);
|
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: | break;
|
215: | default :
|
216: | $content .= '<' . $key . '>' . trim($value) . '</' . $key . '>';
|
217: | break;
|
218: | }
|
219: | }
|
220: | $struct->add('content', new XoopsXmlRpcString($content));
|
221: | $arr->add($struct);
|
222: | unset($struct);
|
223: | }
|
224: | $this->response->add($arr);
|
225: | }
|
226: | } else {
|
227: | $this->response->add(new XoopsXmlRpcFault(106));
|
228: | }
|
229: | }
|
230: | }
|
231: |
|
232: | public function getUsersBlogs()
|
233: | {
|
234: | if (!$this->_checkUser($this->params[1], $this->params[2])) {
|
235: | $this->response->add(new XoopsXmlRpcFault(104));
|
236: | } else {
|
237: | $arr = new XoopsXmlRpcArray();
|
238: | $struct = new XoopsXmlRpcStruct();
|
239: | $struct->add('url', new XoopsXmlRpcString(XOOPS_URL . '/modules/' . $this->module->getVar('dirname') . '/'));
|
240: | $struct->add('blogid', new XoopsXmlRpcString($this->module->getVar('mid')));
|
241: | $struct->add('blogName', new XoopsXmlRpcString('XOOPS Blog'));
|
242: | $arr->add($struct);
|
243: | $this->response->add($arr);
|
244: | }
|
245: | }
|
246: |
|
247: | public function getUserInfo()
|
248: | {
|
249: | if (!$this->_checkUser($this->params[1], $this->params[2])) {
|
250: | $this->response->add(new XoopsXmlRpcFault(104));
|
251: | } else {
|
252: | $struct = new XoopsXmlRpcStruct();
|
253: | $struct->add('nickname', new XoopsXmlRpcString($this->user->getVar('uname')));
|
254: | $struct->add('userid', new XoopsXmlRpcString($this->user->getVar('uid')));
|
255: | $struct->add('url', new XoopsXmlRpcString($this->user->getVar('url')));
|
256: | $struct->add('email', new XoopsXmlRpcString($this->user->getVar('email')));
|
257: | $struct->add('lastname', new XoopsXmlRpcString(''));
|
258: | $struct->add('firstname', new XoopsXmlRpcString($this->user->getVar('name')));
|
259: | $this->response->add($struct);
|
260: | }
|
261: | }
|
262: |
|
263: | public function getTemplate()
|
264: | {
|
265: | if (!$this->_checkUser($this->params[2], $this->params[3])) {
|
266: | $this->response->add(new XoopsXmlRpcFault(104));
|
267: | } else {
|
268: | switch ($this->params[5]) {
|
269: | case 'main':
|
270: | $this->response->add(new XoopsXmlRpcFault(107));
|
271: | break;
|
272: | case 'archiveIndex':
|
273: | $this->response->add(new XoopsXmlRpcFault(107));
|
274: | break;
|
275: | default:
|
276: | $this->response->add(new XoopsXmlRpcFault(107));
|
277: | break;
|
278: | }
|
279: | }
|
280: | }
|
281: |
|
282: | public function setTemplate()
|
283: | {
|
284: | if (!$this->_checkUser($this->params[2], $this->params[3])) {
|
285: | $this->response->add(new XoopsXmlRpcFault(104));
|
286: | } else {
|
287: | $this->response->add(new XoopsXmlRpcFault(107));
|
288: | }
|
289: | }
|
290: | }
|
291: | |