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