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
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @copyright XOOPS Project https://xoops.org/ |
14
|
|
|
* @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
15
|
|
|
* @package |
16
|
|
|
* @since |
17
|
|
|
* @author XOOPS Development Team, Kazumi Ono (AKA onokazu) |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class XoopsXmlRpcApi |
23
|
|
|
*/ |
24
|
|
|
class XoopsXmlRpcApi |
25
|
|
|
{ |
26
|
|
|
// reference to method parameters |
27
|
|
|
public $params; |
28
|
|
|
|
29
|
|
|
// reference to xmlrpc document class object |
30
|
|
|
public $response; |
31
|
|
|
|
32
|
|
|
// reference to module class object |
33
|
|
|
public $module; |
34
|
|
|
|
35
|
|
|
// map between xoops tags and blogger specific tags |
36
|
|
|
public $xoopsTagMap = array(); |
37
|
|
|
|
38
|
|
|
// user class object |
39
|
|
|
public $user; |
40
|
|
|
|
41
|
|
|
public $isadmin = false; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param $params |
45
|
|
|
* @param $response |
46
|
|
|
* @param $module |
47
|
|
|
*/ |
48
|
|
|
public function __construct(&$params, &$response, &$module) |
49
|
|
|
{ |
50
|
|
|
$this->params =& $params; |
51
|
|
|
$this->response =& $response; |
52
|
|
|
$this->module =& $module; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param $user |
57
|
|
|
* @param bool $isadmin |
58
|
|
|
*/ |
59
|
|
|
public function _setUser(&$user, $isadmin = false) |
60
|
|
|
{ |
61
|
|
|
if (is_object($user)) { |
62
|
|
|
$this->user =& $user; |
63
|
|
|
$this->isadmin = $isadmin; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param $username |
69
|
|
|
* @param $password |
70
|
|
|
* |
71
|
|
|
* @return bool |
72
|
|
|
*/ |
73
|
|
|
public function _checkUser($username, $password) |
74
|
|
|
{ |
75
|
|
|
if (isset($this->user)) { |
76
|
|
|
return true; |
77
|
|
|
} |
78
|
|
|
/** @var XoopsMemberHandler $member_handler */ |
79
|
|
|
$member_handler = xoops_getHandler('member'); |
80
|
|
|
$this->user = $member_handler->loginUser(addslashes($username), addslashes($password)); |
81
|
|
|
if (!is_object($this->user)) { |
82
|
|
|
unset($this->user); |
83
|
|
|
|
84
|
|
|
return false; |
85
|
|
|
} |
86
|
|
|
/** @var XoopsGroupPermHandler $moduleperm_handler */ |
87
|
|
|
$moduleperm_handler = xoops_getHandler('groupperm'); |
88
|
|
|
if (!$moduleperm_handler->checkRight('module_read', $this->module->getVar('mid'), $this->user->getGroups())) { |
89
|
|
|
unset($this->user); |
90
|
|
|
|
91
|
|
|
return false; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return true; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return bool |
99
|
|
|
*/ |
100
|
|
|
public function _checkAdmin() |
101
|
|
|
{ |
102
|
|
|
if ($this->isadmin) { |
103
|
|
|
return true; |
104
|
|
|
} |
105
|
|
|
if (!isset($this->user)) { |
106
|
|
|
return false; |
107
|
|
|
} |
108
|
|
|
if (!$this->user->isAdmin($this->module->getVar('mid'))) { |
109
|
|
|
return false; |
110
|
|
|
} |
111
|
|
|
$this->isadmin = true; |
112
|
|
|
|
113
|
|
|
return true; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param null $post_id |
|
|
|
|
118
|
|
|
* @param null $blog_id |
|
|
|
|
119
|
|
|
* |
120
|
|
|
* @return array |
121
|
|
|
*/ |
122
|
|
|
public function &_getPostFields($post_id = null, $blog_id = null) |
|
|
|
|
123
|
|
|
{ |
124
|
|
|
$ret = array(); |
125
|
|
|
$ret['title'] = array('required' => true, 'form_type' => 'textbox', 'value_type' => 'text'); |
126
|
|
|
$ret['hometext'] = array('required' => false, 'form_type' => 'textarea', 'data_type' => 'textarea'); |
127
|
|
|
$ret['moretext'] = array('required' => false, 'form_type' => 'textarea', 'data_type' => 'textarea'); |
128
|
|
|
$ret['categories'] = array('required' => false, 'form_type' => 'select_multi', 'data_type' => 'array'); |
129
|
|
|
|
130
|
|
|
/* |
131
|
|
|
if (!isset($blog_id)) { |
132
|
|
|
if (!isset($post_id)) { |
133
|
|
|
return false; |
134
|
|
|
} |
135
|
|
|
$itemman =& $this->mf->get(MANAGER_ITEM); |
136
|
|
|
$item =& $itemman->get($post_id); |
137
|
|
|
$blog_id = $item->getVar('sect_id'); |
138
|
|
|
} |
139
|
|
|
$sectman =& $this->mf->get(MANAGER_SECTION); |
140
|
|
|
$this->section =& $sectman->get($blog_id); |
141
|
|
|
$ret =& $this->section->getVar('sect_fields'); |
142
|
|
|
*/ |
143
|
|
|
|
144
|
|
|
return $ret; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @param $xoopstag |
149
|
|
|
* @param $blogtag |
150
|
|
|
*/ |
151
|
|
|
public function _setXoopsTagMap($xoopstag, $blogtag) |
152
|
|
|
{ |
153
|
|
|
if (trim($blogtag) != '') { |
154
|
|
|
$this->xoopsTagMap[$xoopstag] = $blogtag; |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param $xoopstag |
160
|
|
|
* |
161
|
|
|
* @return mixed |
162
|
|
|
*/ |
163
|
|
|
public function _getXoopsTagMap($xoopstag) |
164
|
|
|
{ |
165
|
|
|
if (isset($this->xoopsTagMap[$xoopstag])) { |
166
|
|
|
return $this->xoopsTagMap[$xoopstag]; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
return $xoopstag; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param $text |
174
|
|
|
* @param $tag |
175
|
|
|
* @param bool $remove |
176
|
|
|
* |
177
|
|
|
* @return string |
178
|
|
|
*/ |
179
|
|
|
public function _getTagCdata(&$text, $tag, $remove = true) |
180
|
|
|
{ |
181
|
|
|
$ret = ''; |
182
|
|
|
$match = array(); |
183
|
|
|
if (preg_match("/\<" . $tag . "\>(.*)\<\/" . $tag . "\>/is", $text, $match)) { |
184
|
|
|
if ($remove) { |
185
|
|
|
$text = str_replace($match[0], '', $text); |
186
|
|
|
} |
187
|
|
|
$ret = $match[1]; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
return $ret; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
// kind of dirty method to load XOOPS API and create a new object thereof |
194
|
|
|
// returns itself if the calling object is XOOPS API |
195
|
|
|
/** |
196
|
|
|
* @param $params |
197
|
|
|
* |
198
|
|
|
* @return $this|XoopsApi |
199
|
|
|
*/ |
200
|
|
|
public function &_getXoopsApi(&$params) |
201
|
|
|
{ |
202
|
|
|
if (strtolower(get_class($this)) !== 'xoopsapi') { |
203
|
|
|
require_once(XOOPS_ROOT_PATH . '/class/xml/rpc/xoopsapi.php'); |
204
|
|
|
|
205
|
|
|
return new XoopsApi($params, $this->response, $this->module); |
206
|
|
|
} else { |
207
|
|
|
return $this; |
208
|
|
|
} |
209
|
|
|
} |
210
|
|
|
} |
211
|
|
|
|