|
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
|
|
|
use Xoops\Core\Kernel\Handlers\XoopsModule; |
|
|
|
|
|
|
13
|
|
|
use Xoops\Core\Kernel\Handlers\XoopsUser; |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @copyright XOOPS Project (http://xoops.org) |
|
17
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
|
18
|
|
|
* @package class |
|
19
|
|
|
* @subpackage xml |
|
20
|
|
|
* @since 1.0.0 |
|
21
|
|
|
* @author Kazumi Ono (AKA onokazu) |
|
22
|
|
|
* @version $Id $ |
|
23
|
|
|
*/ |
|
24
|
|
|
class XoopsXmlRpcApi |
|
25
|
|
|
{ |
|
26
|
|
|
|
|
27
|
|
|
// reference to method parameters |
|
28
|
|
|
protected $params; |
|
29
|
|
|
|
|
30
|
|
|
// reference to xmlrpc document class object |
|
31
|
|
|
/** |
|
32
|
|
|
* @var XoopsXmlRpcResponse |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $response; |
|
35
|
|
|
|
|
36
|
|
|
// reference to module class object |
|
37
|
|
|
/** |
|
38
|
|
|
* @var XoopsModule |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $module; |
|
41
|
|
|
|
|
42
|
|
|
// map between xoops tags and blogger specific tags |
|
43
|
|
|
protected $xoopsTagMap = array(); |
|
44
|
|
|
|
|
45
|
|
|
// user class object |
|
46
|
|
|
protected $user; |
|
47
|
|
|
|
|
48
|
|
|
protected $isadmin = false; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param $params |
|
52
|
|
|
* @param $response |
|
53
|
|
|
* @param $module |
|
54
|
|
|
*/ |
|
55
|
17 |
|
public function __construct(&$params, &$response, &$module) |
|
56
|
|
|
{ |
|
57
|
17 |
|
$this->params = $params; |
|
58
|
17 |
|
$this->response = $response; |
|
59
|
17 |
|
$this->module = $module; |
|
60
|
17 |
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param $user |
|
64
|
|
|
* @param bool $isadmin |
|
65
|
|
|
*/ |
|
66
|
2 |
|
public function _setUser(&$user, $isadmin = false) |
|
67
|
|
|
{ |
|
68
|
2 |
|
if (is_object($user)) { |
|
69
|
2 |
|
$this->user = $user; |
|
70
|
2 |
|
$this->isadmin = $isadmin; |
|
71
|
|
|
} |
|
72
|
2 |
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @param $username |
|
76
|
|
|
* @param $password |
|
77
|
|
|
* |
|
78
|
|
|
* @return bool |
|
79
|
|
|
*/ |
|
80
|
1 |
|
public function _checkUser($username, $password) |
|
81
|
|
|
{ |
|
82
|
1 |
|
$xoops = Xoops::getInstance(); |
|
83
|
|
|
|
|
84
|
1 |
|
$member_handler = $xoops->getHandlerMember(); |
|
85
|
1 |
|
$this->user = $member_handler->loginUser(addslashes($username), addslashes($password)); |
|
86
|
1 |
|
if (!is_object($this->user)) { |
|
87
|
1 |
|
$this->user = null; |
|
88
|
1 |
|
return false; |
|
89
|
|
|
} |
|
90
|
|
|
$moduleperm_handler = $xoops->getHandlerGroupPermission(); |
|
91
|
|
|
if (!$moduleperm_handler->checkRight('module_read', $this->module->getVar('mid'), $this->user->getGroups())) { |
|
92
|
|
|
$this->user = null; |
|
93
|
|
|
return false; |
|
94
|
|
|
} |
|
95
|
|
|
return true; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @return bool |
|
100
|
|
|
*/ |
|
101
|
1 |
|
public function _checkAdmin() |
|
102
|
|
|
{ |
|
103
|
1 |
|
if ($this->isadmin) { |
|
104
|
1 |
|
return true; |
|
105
|
|
|
} |
|
106
|
1 |
|
if (!is_object($this->user)) { |
|
107
|
1 |
|
return false; |
|
108
|
|
|
} |
|
109
|
|
|
if (!$this->user->isAdmin($this->module->getVar('mid'))) { |
|
110
|
|
|
return false; |
|
111
|
|
|
} |
|
112
|
|
|
$this->isadmin = true; |
|
113
|
|
|
return true; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @param null $post_id |
|
118
|
|
|
* @param null $blog_id |
|
119
|
|
|
* |
|
120
|
|
|
* @return array |
|
121
|
|
|
*/ |
|
122
|
1 |
|
public function &_getPostFields($post_id = null, $blog_id = null) |
|
|
|
|
|
|
123
|
|
|
{ |
|
124
|
1 |
|
$ret = array(); |
|
125
|
1 |
|
$ret['title'] = array('required' => true, 'form_type' => 'textbox', 'value_type' => 'text'); |
|
126
|
1 |
|
$ret['hometext'] = array('required' => false, 'form_type' => 'textarea', 'data_type' => 'textarea'); |
|
127
|
1 |
|
$ret['moretext'] = array('required' => false, 'form_type' => 'textarea', 'data_type' => 'textarea'); |
|
128
|
1 |
|
$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
|
1 |
|
return $ret; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @param string $xoopstag |
|
149
|
|
|
* @param string $blogtag |
|
150
|
|
|
*/ |
|
151
|
8 |
|
public function _setXoopsTagMap($xoopstag, $blogtag) |
|
152
|
|
|
{ |
|
153
|
8 |
|
if (trim($blogtag) != '') { |
|
154
|
8 |
|
$this->xoopsTagMap[$xoopstag] = $blogtag; |
|
155
|
|
|
} |
|
156
|
8 |
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @param $xoopstag |
|
160
|
|
|
* |
|
161
|
|
|
* @return mixed |
|
162
|
|
|
*/ |
|
163
|
1 |
|
public function _getXoopsTagMap($xoopstag) |
|
164
|
|
|
{ |
|
165
|
1 |
|
if (isset($this->xoopsTagMap[$xoopstag])) { |
|
166
|
1 |
|
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
|
1 |
|
public function _getTagCdata(&$text, $tag, $remove = true) |
|
180
|
|
|
{ |
|
181
|
1 |
|
$ret = ''; |
|
182
|
1 |
|
$match = array(); |
|
183
|
1 |
|
if (preg_match("/\<" . $tag . "\>(.*)\<\/" . $tag . "\>/is", $text, $match)) { |
|
184
|
1 |
|
if ($remove) { |
|
185
|
1 |
|
$text = str_replace($match[0], '', $text); |
|
186
|
|
|
} |
|
187
|
1 |
|
$ret = $match[1]; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
1 |
|
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 XoopsApi |
|
199
|
|
|
*/ |
|
200
|
1 |
|
public function _getXoopsApi(&$params) |
|
201
|
|
|
{ |
|
202
|
1 |
|
if (strtolower(get_class($this)) !== 'xoopsapi') { |
|
203
|
1 |
|
$xoops_root_path = \XoopsBaseConfig::get('root-path'); |
|
204
|
1 |
|
require_once($xoops_root_path . '/class/xml/rpc/xoopsapi.php'); |
|
205
|
1 |
|
return new XoopsApi($params, $this->response, $this->module); |
|
206
|
|
|
} else { |
|
207
|
|
|
return $this; |
|
208
|
|
|
} |
|
209
|
|
|
} |
|
210
|
|
|
} |
|
211
|
|
|
|
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: