-
Notifications
You must be signed in to change notification settings - Fork 3
/
plxMyPluginDownloader.php
executable file
·231 lines (200 loc) · 6.99 KB
/
plxMyPluginDownloader.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
<?php
/**
* Plugin plxMyPluginDownloader
*
* @author Stephane F
**/
class plxMyPluginDownloader extends plxPlugin {
/**
* Constructeur de la classe
*
* @param default_lang langue par défaut
* @return stdio
* @author Stephane F
**/
public function __construct($default_lang) {
# appel du constructeur de la classe plxPlugin (obligatoire)
parent::__construct($default_lang);
# droits pour accèder à la page config.php
$this->setConfigProfil(PROFIL_ADMIN);
# droits pour accèder à la page admin.php
$this->setAdminProfil(PROFIL_ADMIN);
# déclaration des hooks
$this->addHook('AdminTopEndHead', 'AdminTopEndHead');
$this->addHook('AdminTopBottom', 'AdminTopBottom');
}
/**
* Méthode appelée à l'activation du plugin pour créer le répertoire cache
*
* @author Stephane F
**/
public function onActivate() {
if(!is_dir(PLX_PLUGINS.'/cache')) {
mkdir(PLX_PLUGINS.'/cache',0755,true);
}
}
/**
* Méthode qui ajoute la déclaration de la feuille de style pour l'écran d'admin du plugin
*
* @return stdio
* @author Stephane F
**/
public function AdminTopEndHead() {
echo '<link rel="stylesheet" type="text/css" href="'.PLX_PLUGINS.'plxMyPluginDownloader/css/style.css" />'."\n";
}
/**
* Méthode qui effectue les contrôles pour le fonctionnement du plugin
*
* @return stdio
* @author Stephane F
**/
public function AdminTopBottom() {
$string = '
$test1 = plxMyPluginDownloader::is_cURL();
$test2 = is_dir(PLX_PLUGINS);
$test3 = is_writable(PLX_PLUGINS);
if(!$test1 OR !$test2 OR !$test3) {
echo "<p class=\"warning\">Plugin MyPluginDownloader<br />";
if(!$test1) echo "<br />'.$this->getLang('L_ERR_CURL').'";
if(!$test2) echo "<br />'.$this->getLang('L_ERR_PLX_PLUGINS').'";
if($test2 AND !$test3) echo "<br />'.$this->getLang('L_ERR_WRITE_ACCESS').'";
echo "</p>";
plxMsg::Display();
}
';
echo '<?php '.$string.' ?>';
}
/***************************************************/
/* méthodes publiques pour télécharger des plugins */
/***************************************************/
public static function is_cURL() {
return in_array("curl", get_loaded_extensions());
}
public static function getRemoteFileContent($remotefile){
$curl = curl_init($remotefile);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
curl_close($curl);
if ($result !== false){
return $result;
}
return false;
}
public static function is_RemoteFileExists($remotefile) {
return true;
// Version 4.x supported
$curl = curl_init($remotefile);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); // request as if Firefox
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, false);
$connectable = curl_exec($curl);
curl_close($curl);
return $connectable;
}
public static function downloadRemoteFile($remotefile, $destination,$VerifyPeer=false,$VerifyHost=true) {
if($fp = fopen($destination, 'w')) {
$curl = curl_init($remotefile);
curl_setopt($curl, CURLOPT_FILE, $fp);
curl_setopt($curl, CURLOPT_HEADER, 0); # we are not sending any headers
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
plxMyPluginDownloader::curl_redir_exec($curl);
curl_close($curl);
fclose($fp);
}
else return false;
return (is_file($destination) AND filesize($destination)>0);
}
public static function getRepository($filename) {
$array=array();
# Mise en place du parseur XML
$data = implode('',file($filename));
$parser = xml_parser_create(PLX_CHARSET);
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,0);
xml_parse_into_struct($parser,$data,$values,$iTags);
xml_parser_free($parser);
# Récupération des données xml
if(isset($iTags['plugin'])) {
$nb = sizeof($iTags['name']);
for($i = 0; $i < $nb; $i++) {
$name = plxUtils::getValue($values[$iTags['name'][$i]]['value']);
if($name!='') {
$array[$name]['name'] = $name;
$array[$name]['title'] = plxUtils::getValue($values[$iTags['title'][$i]]['value']);
$array[$name]['author'] = plxUtils::getValue($values[$iTags['author'][$i]]['value']);
$array[$name]['version'] = plxUtils::getValue($values[$iTags['version'][$i]]['value']);
$array[$name]['date'] = plxUtils::getValue($values[$iTags['date'][$i]]['value']);
$array[$name]['site'] = plxUtils::getValue($values[$iTags['site'][$i]]['value']);
$array[$name]['description'] = plxUtils::getValue($values[$iTags['description'][$i]]['value']);
$array[$name]['file'] = plxUtils::getValue($values[$iTags['file'][$i]]['value']);
$array[$name]['icon'] = plxUtils::getValue($values[$iTags['icon'][$i]]['value']);
}
}
}
return $array;
}
public static function ini_get_boolean($setting) {
$my_boolean = ini_get($setting);
if ((int) $my_boolean > 0)
$my_boolean = true;
else {
$my_lowered_boolean = strtolower($my_boolean);
if ($my_lowered_boolean === "true" || $my_lowered_boolean === "on" || $my_lowered_boolean === "yes")
$my_boolean = true;
else
$my_boolean = false;
}
return $my_boolean;
}
public static function curl_redir_exec(/*resource*/ $ch, /*int*/ &$maxredirect = null) {
$mr = $maxredirect === null ? 5 : intval($maxredirect);
if (ini_get('open_basedir') == '' && !plxMyPluginDownloader::ini_get_boolean('safe_mode')) {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $mr > 0);
curl_setopt($ch, CURLOPT_MAXREDIRS, $mr);
} else {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
if ($mr > 0) {
$newurl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
$rch = curl_copy_handle($ch);
curl_setopt($rch, CURLOPT_HEADER, true);
curl_setopt($rch, CURLOPT_NOBODY, true);
curl_setopt($rch, CURLOPT_FORBID_REUSE, false);
curl_setopt($rch, CURLOPT_RETURNTRANSFER, true);
do {
curl_setopt($rch, CURLOPT_URL, $newurl);
$header = curl_exec($rch);
if (curl_errno($rch)) {
$code = 0;
} else {
$code = curl_getinfo($rch, CURLINFO_HTTP_CODE);
if ($code == 301 || $code == 302) {
preg_match('/Location:(.*?)\n/', $header, $matches);
$newurl = trim(array_pop($matches));
} else {
$code = 0;
}
}
} while ($code && --$mr);
curl_close($rch);
if (!$mr) {
if ($maxredirect === null) {
trigger_error('Too many redirects. When following redirects, libcurl hit the maximum amount.', E_USER_WARNING);
} else {
$maxredirect = 0;
}
return false;
}
curl_setopt($ch, CURLOPT_URL, $newurl);
}
}
return curl_exec($ch);
}
}
?>