-
Notifications
You must be signed in to change notification settings - Fork 0
/
xml.php
96 lines (68 loc) · 2.76 KB
/
xml.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
<?php
/*Stáhne z improligy xml dump
*/
define("CZK",
"říšňěžťčýůúěďóéáŘÍŠŇĚŽŤČÝÚŮĚĎÓÉÁ"
);
//<form method="post" action="/index.php?title=Specmakei%C3%A1ln%C3%AD:Exportovat_str%C3%A1nky&action=submit">
//<br /><textarea name="pages" cols="40" rows="10"></textarea><br />
//<input name="curonly" type="checkbox" value="1" checked="checked" id="curonly" /> <label for="curonly">Zahrnout jen současnou verzi, ne plnou historii</label><br />
//<input name="templates" type="checkbox" value="1" id="wpExportTemplates" /> <label for="wpExportTemplates">Zahrnout šablony</label><br />
//<input name="wpDownload" type="checkbox" value="1" checked="checked" id="wpDownload" /> <label for="wpDownload">Nabídnout uložení jako soubor</label><br />
//<input type="submit" value="Exportovat" title="[s]" accesskey="s" /></form></div>
function load_list($url){
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
//curl_setopt($ch,CURLOPT_POST, count($fields));
//curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
ob_start();
$result = curl_exec($ch);
$data= ob_get_contents();
curl_close($ch);
ob_end_clean();
$p_start= strpos($data,'<td class="mw-allpages-nav">');
$p_end=strpos($data,'<div class="printfooter">',$p_start);
$data=substr($data,$p_start,$p_end -$p_start);
preg_match_all("~\>([[:alnum:]\ \_\(\)\-\&\:\,\/\.".CZK."]*)\<~",$data,$result);
return implode ("\n",$result[1]);
}
$seznam="";
$urls=array(
"https://wiki.improliga.cz/wiki/Speci%C3%A1ln%C3%AD:V%C5%A1echny_str%C3%A1nky",
"https://wiki.improliga.cz/index.php?title=Speci%C3%A1ln%C3%AD:V%C5%A1echny_str%C3%A1nky&namespace=2",
"https://wiki.improliga.cz/index.php?title=Speci%C3%A1ln%C3%AD:V%C5%A1echny_str%C3%A1nky&namespace=14",
);
foreach($urls as $url){
$seznam.="\n".load_list ($url);
}
file_put_contents("seznam.txt",$seznam);
//set POST variables
$url = 'https://wiki.improliga.cz/index.php?title=Speci%C3%A1ln%C3%AD:Exportovat_str%C3%A1nky&action=submit';
$fields = array();
$fields["pages"]=urlencode($seznam);
$fields["curonly"]="checked";
$fields["wpDownload"]="checked";
$fields_string="";
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
ob_start();
$result = curl_exec($ch);
$data= ob_get_contents();
curl_close($ch);
ob_end_clean();
//var_export(curl_getinfo($ch));
//close connection
if($result){
file_put_contents("wiki.xml",$data);
}