-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxmlrpc.php
272 lines (243 loc) · 7.52 KB
/
xmlrpc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<?php
include_once("functions.php");
include_once("shared.php");
include_once("include/xmlrpc/IXR.php");
//metaWeblog.newPost (blogid, username, password, struct, publish) returns string
/*function newPost($args) { // funzione obsoleta
$addr = getparam("REMOTE_ADDR", PAR_SERVER, SAN_FLAT);
$blogid = $args[0];
$username = $args[1];
$password = $args[2];
$struct = $args[3];
$publish = $args[4];
$r_pass = getpass($username);
if($r_pass == null)
return null;
else {
if($r_pass != md5($password))
return null;
}
if(getlevel($username, "home") == 10){
$struct['title'] = ($struct['title']!="") ? ($struct['title']) : ("New post");
$string = "<?xml version='1.0'?>\n";
$string .= "<!DOCTYPE fn:news SYSTEM \"http://flatnuke.sourceforge.net/dtd/news.dtd\">\n";
$string .= "<fn:news xmlns:fn=\"http://flatnuke.sourceforge.net/news\">\n";
$string .= "\t<fn:title>".$struct['title']."</fn:title>\n";
$string .= "\t<fn:avatar>".$struct['categories'][0].".png</fn:avatar>\n";
$string .= "\t<fn:reads>0</fn:reads>\n";
$string .= "\t<fn:header>".$struct['description']."</fn:header>\n";
$string .= "\t<fn:body></fn:body>\n";
$string .= "</fn:news>";
$postid = time();
fnwrite("news/".$postid.".xml", $string, "w", array("nonull"));
fnlog("News", $addr."||".$username."||News $postid published.");
//generate_RSS(); // needs to be replaced ...
return ($postid);
}
return null;
}*/
/*
1. appkey (string): Unique identifier/passcode of the application sending the post. (See access info.)
2. username (string): Login for the Blogger user who's blogs will be retrieved.
3. password (string): Password for said username.
*/
function getUsersBlogs($args) {
include "config.php";
$addr = getparam("REMOTE_ADDR", PAR_SERVER, SAN_FLAT);
$blogid = $args[0];
$username = $args[1];
$password = $args[2];
$r_pass = getpass($username);
if($r_pass == null)
return null;
else {
if($r_pass != md5($password))
return null;
}
$a = array();
$a['url'] = $addr;
$a['blogid'] = "1";
$a['blogName'] = $sitename;
$b = array($a);
return($b);
}
//metaWeblog.getCategories (blogid, username, password) returns array
function getCategories($args) {
$addr = getparam("REMOTE_ADDR", PAR_SERVER, SAN_FLAT);
$blogid = $args[0];
$username = $args[1];
$password = $args[2];
$r_pass = getpass($username);
if($r_pass == null)
return null;
else {
if($r_pass != md5($password))
return null;
}
$modlist = array();
$handle = opendir('images/news');
while ($file = readdir($handle)) {
if (!( $file=="." or $file==".." ) and (!preg_match("/^\./",$file)and ($file!="CVS")) ) {
array_push($modlist, $file);
}
}
closedir($handle);
if(count($modlist)>0)
sort($modlist);
$b = array();
for ($i=0; $i < count($modlist); $i++) {
$a = array();
$a['description'] = str_replace("_"," ", preg_replace("/\..*/","",$modlist[$i]));
$a['categoryName'] = str_replace("_"," ", preg_replace("/\..*/","",$modlist[$i]));
$a['htmlUrl'] = "#";
$a['rssUrl'] = "#";
$b[$i] = $a;
}
return($b);
}
//metaWeblog.newPost (blogid, username, password, n.post) returns array
/*function getRecentPosts($args) { // funzione obsoleta
$blogid = $args[0];
$username = $args[1];
$password = $args[2];
$npost = $args[3];
$r_pass = getpass($username);
if($r_pass == null)
return null;
else {
if($r_pass != md5($password))
return null;
}
$modlist = array();
$handle = opendir('news');
while ($file = readdir($handle)) {
if (!( $file=="." or $file==".." ) and (!preg_match("/^\./",$file) and ($file!="CVS")) and preg_match("/xml$/i",get_file_extension($file)) ) {
array_push($modlist, $file);
}
}
closedir($handle);
if(count($modlist)>0)
rsort($modlist);
if($npost > count($modlist))
$npost = count($modlist);
$b = array();
for ($i=0; $i < $npost; $i++) {
$fd = get_file("news/".$modlist[$i]);
$postid = str_replace(".xml", "", $modlist[$i]);
$header = utf8_encode(get_xml_element("fn:header",$fd));
$title = utf8_encode(get_xml_element("fn:title",$fd));
$cat = str_replace(".png","", get_xml_element("fn:avatar",$fd));
$a = array();
$dt = date('Ymd',$postid)."T".date('H:i:s', $postid);
$dt = new IXR_Date($dt);
$a['description'] = $header;
$a['dateCreated'] = $dt;
$a['title'] = $title;
$a['postid'] = $postid;
$c = array();
$c[0] = $cat;
$a['categories'] = $c;
$b[$i] = $a;
}
return $b;
}*/
//metaWeblog.editPost (postid, username, password, struct, publish) returns boolean
/*function editPost($args) { // funzione obsoleta
$postid = $args[0];
$username = $args[1];
$password = $args[2];
$struct = $args[3];
$publish = $args[4];
$r_pass = getpass($username);
if($r_pass == null)
return null;
else {
if($r_pass != md5($password))
return null;
}
if(getlevel($username, "home") == 10){
$lockfile = "news/$postid.xml";
$string = get_file($lockfile);
$string = preg_replace("/<fn:title>.*<\/fn:title>/i","<fn:title>".$struct['title']."</fn:title>",$string);
$string = preg_replace("/<fn:avatar>.*<\/fn:avatar>/i","<fn:avatar>".$struct['categories'][0].".png</fn:avatar>",$string);
$string = preg_replace("/<fn:header>.*<\/fn:header>/i","<fn:header>".$struct['description']."</fn:header>",$string);
fnwrite($lockfile, $string, "w", array("nonull"));
} else {
return false;
}
return true;
}*/
//metaWeblog.editPost (postid, username, password) returns array
/*function getPost($args) { // funzione obsoleta
$postid = $args[0];
$username = $args[1];
$password = $args[2];
if(!file_exists("news/$postid.xml"))
return null;
$r_pass = getpass($username);
if($r_pass == null)
return null;
else {
if($r_pass != md5($password))
return null;
}
$fd = get_file("news/$postid.xml");
$header = get_xml_element("fn:header",$fd);
$title = get_xml_element("fn:title",$fd);
$cat = str_replace(".png","", get_xml_element("fn:avatar",$fd));
$a = array();
$dt = date('Ymd',$postid)."T".date('H:i:s', $postid);
$dt = new IXR_Date($dt);
$a['description'] = $header;
$a['dateCreated'] = $dt;
$a['title'] = $title;
$a['postid'] = $postid;
$c = array();
$c[0] = $cat;
$a['categories'] = $c;
return($a);
}*/
/*
0. appkey : currently ignored
1. postId : postId is a unique identifier for the post created. It is the value returned by blogger.newPost. postId will look like..."zoneId|convId|pathToWeblog|msgNum".
2. username : the email address you use as a username for the site. This user must have privileges to post to the weblog as either the weblog owner, or a member of the owner group.
3. password : the password you use for the site
4. publish : true/false. Ignored.
*/
/*function deletePost($args) { // funzione obsoleta
$appkey = $args[0];
$postid = $args[1];
$username = $args[2];
$password = $args[3];
$publish = $args[4];
// security checks
$addr = getparam("REMOTE_ADDR", PAR_SERVER, SAN_FLAT);
$r_pass = getpass($username);
if($r_pass == null)
return null;
else {
if($r_pass != md5($password))
return null;
}
// check file exists
if(!file_exists("news/$postid.xml"))
return false;
// only admin can delete
if(getlevel($username, "home") == 10){
unlink("news/$postid.xml");
fnlog("News", $postid."||".$username."||Deleted news $postid.");
return true;
} else {
return false;
}
}*/
$server = new IXR_Server(array(
'metaWeblog.getPost' => 'getPost',
'metaWeblog.newPost' => 'newPost',
'metaWeblog.editPost' => 'editPost',
'blogger.getUsersBlogs' => 'getUsersBlogs',
'metaWeblog.getRecentPosts' => 'getRecentPosts',
'metaWeblog.getCategories' => 'getCategories',
'metaWeblog.deletePost' => 'deletePost'
));
?>