1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: use Xoops\Core\Kernel\Handlers\XoopsModule;
13: use Xoops\Core\Kernel\Handlers\XoopsUser;
14:
15: 16: 17: 18: 19: 20: 21: 22: 23:
24:
25: class XoopsXmlRpcApi
26: {
27:
28:
29: protected $params;
30:
31:
32: 33: 34:
35: protected $response;
36:
37:
38: 39: 40:
41: protected $module;
42:
43:
44: protected $xoopsTagMap = array();
45:
46:
47: protected $user;
48:
49: protected $isadmin = false;
50:
51:
52: function XoopsXmlRpcApi(array &$params, XoopsXmlRpcResponse $response, XoopsModule $module)
53: {
54: $this->params = $params;
55: $this->response = $response;
56: $this->module = $module;
57: }
58:
59: function _setUser(XoopsUser $user, $isadmin = false)
60: {
61: if (is_object($user)) {
62: $this->user = $user;
63: $this->isadmin = $isadmin;
64: }
65: }
66:
67: function _checkUser($username, $password)
68: {
69: $xoops = Xoops::getInstance();
70:
71: $member_handler = $xoops->getHandlerMember();
72: $this->user = $member_handler->loginUser(addslashes($username), addslashes($password));
73: if (!is_object($this->user)) {
74: $this->user = null;
75: return false;
76: }
77: $moduleperm_handler = $xoops->getHandlerGroupPermission();
78: if (!$moduleperm_handler->checkRight('module_read', $this->module->getVar('mid'), $this->user->getGroups())) {
79: $this->user = null;
80: return false;
81: }
82: return true;
83: }
84:
85: function _checkAdmin()
86: {
87: if ($this->isadmin) {
88: return true;
89: }
90: if (!is_object($this->user)) {
91: return false;
92: }
93: if (!$this->user->isAdmin($this->module->getVar('mid'))) {
94: return false;
95: }
96: $this->isadmin = true;
97: return true;
98: }
99:
100: function _getPostFields($post_id = null, $blog_id = null)
101: {
102: $ret = array();
103: $ret['title'] = array('required' => true, 'form_type' => 'textbox', 'value_type' => 'text');
104: $ret['hometext'] = array('required' => false, 'form_type' => 'textarea', 'data_type' => 'textarea');
105: $ret['moretext'] = array('required' => false, 'form_type' => 'textarea', 'data_type' => 'textarea');
106: $ret['categories'] = array('required' => false, 'form_type' => 'select_multi', 'data_type' => 'array');
107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119:
120: return $ret;
121: }
122:
123: 124: 125: 126:
127: function _setXoopsTagMap($xoopstag, $blogtag)
128: {
129: if (trim($blogtag) != '') {
130: $this->xoopsTagMap[$xoopstag] = $blogtag;
131: }
132: }
133:
134: function _getXoopsTagMap($xoopstag)
135: {
136: if (isset($this->xoopsTagMap[$xoopstag])) {
137: return $this->xoopsTagMap[$xoopstag];
138: }
139: return $xoopstag;
140: }
141:
142: function _getTagCdata(&$text, $tag, $remove = true)
143: {
144: $ret = '';
145: $match = array();
146: if (preg_match("/\<" . $tag . "\>(.*)\<\/" . $tag . "\>/is", $text, $match)) {
147: if ($remove) {
148: $text = str_replace($match[0], '', $text);
149: }
150: $ret = $match[1];
151: }
152: return $ret;
153: }
154:
155:
156:
157: function _getXoopsApi(&$params)
158: {
159: if (strtolower(get_class($this)) !== 'xoopsapi') {
160: $xoops_root_path = \XoopsBaseConfig::get('root-path');
161: require_once($xoops_root_path . '/class/xml/rpc/xoopsapi.php');
162: return new XoopsApi($params, $this->response, $this->module);
163: } else {
164: return $this;
165: }
166: }
167: }
168: