forked from AbdouBenBerrah/Wordpress.org-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScrap.php
More file actions
167 lines (127 loc) · 5.34 KB
/
Copy pathScrap.php
File metadata and controls
167 lines (127 loc) · 5.34 KB
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
<?php
class Wordpress {
private $debug = FALSE;
private $urlDefaultOpts = [
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_SSL_VERIFYHOST => FALSE,
CURLOPT_TIMEOUT => 3,
CURLOPT_VERBOSE => FALSE,
CURLOPT_HEADER => TRUE,
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906 Firefox/3.0',
CURLOPT_AUTOREFERER => FALSE,
CURLOPT_NOBODY => FALSE,
CURLOPT_HTTPPROXYTUNNEL => FALSE,
CURLOPT_PROXY => ''
];
public function __construct() {
if ( in_array ( 'curl', @get_loaded_extensions()) === FALSE || extension_loaded ( 'curl' ) === FALSE )
trigger_error ( 'CURL Lib not loaded', E_USER_ERROR );
return TRUE;
}
public function getCount(){
$url = "https://fr.wordpress.org/plugins/";
if ( ( $content = self::get($url) ) == FALSE ) {
return FALSE;
}
if ( preg_match('/WordPress\s(\w*)\s([\d,]*)\sext/i', $content, $return) == FALSE ){
if ( $this -> debug === TRUE ){
trigger_error("Can not parse html returned", E_USER_ERROR );
}
return FALSE;
}
$count = @str_replace(',','.',(string)$return[2]);
return $count;
}
public function pluginDetail($url){
//https://fr.wordpress.org/plugins/?p=42561
if ( ( $content = self::get($url) ) == FALSE ) {
return FALSE;
}
if ( @preg_match('@<\s*?script\stype=["\']application\/ld\+json["\'][^>]*>(.*?)</script\b[^>]*@s', $content, $return) == FALSE ){
if ( $this -> debug === TRUE ){
trigger_error("No Json infos !", E_USER_ERROR );
}
return FALSE;
}
if ( ( $json = @json_decode($return[1], true) ) == FALSE ) {
if ( $this -> debug === TRUE ){
trigger_error("Json malformed !", E_USER_ERROR );
}
return FALSE;
}
$pluginInfos = [
"name" => @$json[1]["name"],
"description" => @$json[1]["description"],
"softwareVersion" => @$json[1]["softwareVersion"],
"downloadUrl" => @$json[1]["downloadUrl"],
"dateModified" => @$json[1]["dateModified"]
];
return $pluginInfos;
}
public function search($keyword){
$url = ('https://fr.wordpress.org/plugins/search/'.urlencode((string)$keyword).'/page/1/');
$regex_next = '/a\sclass=["\']next\spage-numbers["\']\shref=["\'](.*?)["\']/i';
$regex_link = '/<h2\sclass=["\']entry-title["\']><a\shref=["\'](.*?)["\']\srel=["\']bookmark["\']>/i';
$linksArray = array();
if ( ( $content = self::get($url) ) == FALSE ) {
return FALSE;
}
if ( @preg_match_all($regex_link, $content, $links) == FALSE ){
if ( $this -> debug === TRUE ){
trigger_error("No result !", E_USER_ERROR );
}
return FALSE;
}
if ( count((array)$links[1]) < 1 ){
if ( $this -> debug === TRUE ){
trigger_error("No result 2 !", E_USER_ERROR );
}
return FALSE;
}
$linkArray = (array)$links[1];
while ( ( @preg_match($regex_next, $content, $return) ) != FALSE ){
if ( ( $content = self::get($return[1]) ) != FALSE ) {
@preg_match_all($regex_link, $content, $links);
$linkArray = array_merge($linkArray,(array)$links[1]);
}
else break;
}
$linkArray = array_unique($linkArray);
return $linkArray;
}
private function get($url,array $opt = []) {
$link = @curl_init($url);
curl_setopt_array($link, ($this->urlDefaultOpts+$opt));
if(($result = @curl_exec($link)) == FALSE ){
if ( $this -> debug === TRUE ) {
$curl_errno = @curl_errno($link);
$curl_error = @curl_error($link);
trigger_error("cURL Error ($curl_errno): $curl_error", E_USER_ERROR );
}
@curl_close($link);
return FALSE;
}
@curl_close($link);
return $result;
}
}
// Try :
//$A = new Wordpress();
//var_dump($A -> getCount());
//var_dump($A -> search('wp'));
//var_dump($A -> pluginDetail("https://fr.wordpress.org/plugins/wpforms-lite/"));
// Use Case : Download all plugins from wordpress.org
/*
$A = new Wordpress();
for($i = 0; $i < 50000; $i++){
if (($infos = $A -> pluginDetail('https://fr.wordpress.org/plugins/?p='.$i)) != FALSE ){
$dir = str_replace('.zip','',basename($infos["downloadUrl"]));
@mkdir($dir);
@file_put_contents(('./'.$dir.'/report.txt'), var_export($infos, true));
@system(('wget '.escapeshellarg($infos["downloadUrl"]).' -P '.$dir.' &'));
}
}
*/
?>