1 | <?php |
---|
2 | class floOS |
---|
3 | { |
---|
4 | var $is_nutd = array(); |
---|
5 | function floOS_version_compare($a, $b) |
---|
6 | { |
---|
7 | $pattern = array('/([a-z])/ei', '/\.+/', '/\.\Z|\A\./'); |
---|
8 | $replacement = array( "'.'.intval('\\1', 36).'.'", '.', ''); |
---|
9 | |
---|
10 | $array = preg_replace($pattern, $replacement, array($a, $b)); |
---|
11 | |
---|
12 | return version_compare($array[0], $array[1], '>='); |
---|
13 | } |
---|
14 | function theme_version_search($dir) |
---|
15 | { |
---|
16 | global $template, $page; |
---|
17 | load_language('template.lang', PHPWG_ROOT_PATH.'template/floOS/tools/'); |
---|
18 | $header_msgs = array(); |
---|
19 | $dh = opendir ($dir); |
---|
20 | while (($file = readdir ($dh)) !== false ) { |
---|
21 | if ($file !== '.' && $file !== '..' && $file !== '.svn') { // enleve svn |
---|
22 | $path =$dir.'/'.$file; |
---|
23 | if (is_dir($path)) { |
---|
24 | $this->theme_version_search($path); |
---|
25 | } |
---|
26 | else |
---|
27 | { |
---|
28 | $page = explode('.', $file); |
---|
29 | $nb = count($page); |
---|
30 | $nom_fichier = $page[0]; |
---|
31 | for ($i = 1; $i < $nb-1; $i++){ |
---|
32 | $nom_fichier .= '.'.$page[$i]; |
---|
33 | } |
---|
34 | if(isset($page[1])){ |
---|
35 | $ext_fichier = $page[$nb-1]; |
---|
36 | } |
---|
37 | else { |
---|
38 | $ext_fichier = ''; |
---|
39 | } |
---|
40 | if($nom_fichier == 'themeconf.inc' and $ext_fichier == 'php') { |
---|
41 | include($path); |
---|
42 | if (isset($themeconf['eid'])) |
---|
43 | { |
---|
44 | if($this->is_not_up_to_date($themeconf['version'],$themeconf['eid']) ) |
---|
45 | { |
---|
46 | |
---|
47 | $msg=l10n('theme_update_needed_1').$themeconf['theme'].l10n('theme_update_needed_2').$themeconf['eid'].l10n('theme_update_needed_3').$themeconf['theme'].l10n('theme_update_needed_4'); |
---|
48 | $template->append('header_notes', $msg); |
---|
49 | $this->is_nutd[$themeconf['theme']]=$themeconf['version']; |
---|
50 | } |
---|
51 | } |
---|
52 | |
---|
53 | } |
---|
54 | } |
---|
55 | } |
---|
56 | } |
---|
57 | closedir ($dh); // on ferme le repertoire courant |
---|
58 | } |
---|
59 | function url_is_remote($url) |
---|
60 | { |
---|
61 | if ( strncmp($url, 'http://', 7)==0 |
---|
62 | or strncmp($url, 'https://', 8)==0 ) |
---|
63 | { |
---|
64 | return true; |
---|
65 | } |
---|
66 | return false; |
---|
67 | } |
---|
68 | |
---|
69 | function fetchRemote($src, &$dest, $user_agent='Piwigo', $step=0) |
---|
70 | { |
---|
71 | // Try to retrieve data from local file? |
---|
72 | if (!$this->url_is_remote($src)) |
---|
73 | { |
---|
74 | $content = @file_get_contents($src); |
---|
75 | if ($content !== false) |
---|
76 | { |
---|
77 | is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; |
---|
78 | return true; |
---|
79 | } |
---|
80 | else |
---|
81 | { |
---|
82 | return false; |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | // After 3 redirections, return false |
---|
87 | if ($step > 3) return false; |
---|
88 | |
---|
89 | // Initialize $dest |
---|
90 | is_resource($dest) or $dest = ''; |
---|
91 | |
---|
92 | // Try curl to read remote file |
---|
93 | if (function_exists('curl_init')) |
---|
94 | { |
---|
95 | $ch = @curl_init(); |
---|
96 | @curl_setopt($ch, CURLOPT_URL, $src); |
---|
97 | @curl_setopt($ch, CURLOPT_HEADER, 1); |
---|
98 | @curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); |
---|
99 | @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
---|
100 | $content = @curl_exec($ch); |
---|
101 | $header_length = @curl_getinfo($ch, CURLINFO_HEADER_SIZE); |
---|
102 | $status = @curl_getinfo($ch, CURLINFO_HTTP_CODE); |
---|
103 | @curl_close($ch); |
---|
104 | if ($content !== false and $status >= 200 and $status < 400) |
---|
105 | { |
---|
106 | if (preg_match('/Location:\s+?(.+)/', substr($content, 0, $header_length), $m)) |
---|
107 | { |
---|
108 | return $this->fetchRemote($m[1], $dest, $user_agent, $step+1); |
---|
109 | } |
---|
110 | $content = substr($content, $header_length); |
---|
111 | is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; |
---|
112 | return true; |
---|
113 | } |
---|
114 | } |
---|
115 | |
---|
116 | // Try file_get_contents to read remote file |
---|
117 | if (ini_get('allow_url_fopen')) |
---|
118 | { |
---|
119 | $content = @file_get_contents($src); |
---|
120 | if ($content !== false) |
---|
121 | { |
---|
122 | is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; |
---|
123 | return true; |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | // Try fsockopen to read remote file |
---|
128 | $src = parse_url($src); |
---|
129 | $host = $src['host']; |
---|
130 | $path = isset($src['path']) ? $src['path'] : '/'; |
---|
131 | $path .= isset($src['query']) ? '?'.$src['query'] : ''; |
---|
132 | |
---|
133 | if (($s = @fsockopen($host,80,$errno,$errstr,5)) === false) |
---|
134 | { |
---|
135 | return false; |
---|
136 | } |
---|
137 | |
---|
138 | fwrite($s, |
---|
139 | "GET ".$path." HTTP/1.0\r\n" |
---|
140 | ."Host: ".$host."\r\n" |
---|
141 | ."User-Agent: ".$user_agent."\r\n" |
---|
142 | ."Accept: */*\r\n" |
---|
143 | ."\r\n" |
---|
144 | ); |
---|
145 | |
---|
146 | $i = 0; |
---|
147 | $in_content = false; |
---|
148 | while (!feof($s)) |
---|
149 | { |
---|
150 | $line = fgets($s); |
---|
151 | |
---|
152 | if (rtrim($line,"\r\n") == '' && !$in_content) |
---|
153 | { |
---|
154 | $in_content = true; |
---|
155 | $i++; |
---|
156 | continue; |
---|
157 | } |
---|
158 | if ($i == 0) |
---|
159 | { |
---|
160 | if (!preg_match('/HTTP\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/',rtrim($line,"\r\n"), $m)) |
---|
161 | { |
---|
162 | fclose($s); |
---|
163 | return false; |
---|
164 | } |
---|
165 | $status = (integer) $m[2]; |
---|
166 | if ($status < 200 || $status >= 400) |
---|
167 | { |
---|
168 | fclose($s); |
---|
169 | return false; |
---|
170 | } |
---|
171 | } |
---|
172 | if (!$in_content) |
---|
173 | { |
---|
174 | if (preg_match('/Location:\s+?(.+)$/',rtrim($line,"\r\n"),$m)) |
---|
175 | { |
---|
176 | fclose($s); |
---|
177 | return $this->fetchRemote(trim($m[1]),$dest,$user_agent,$step+1); |
---|
178 | } |
---|
179 | $i++; |
---|
180 | continue; |
---|
181 | } |
---|
182 | is_resource($dest) ? @fwrite($dest, $line) : $dest .= $line; |
---|
183 | $i++; |
---|
184 | } |
---|
185 | fclose($s); |
---|
186 | return true; |
---|
187 | } |
---|
188 | |
---|
189 | |
---|
190 | function is_not_up_to_date($v_local, $eid) |
---|
191 | { |
---|
192 | |
---|
193 | global $template, $user, $page; |
---|
194 | // include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
195 | |
---|
196 | load_language('template.lang', PHPWG_ROOT_PATH.'template/floOS/tools/'); |
---|
197 | |
---|
198 | // Retrieve PEM versions |
---|
199 | $version = PHPWG_VERSION; |
---|
200 | $versions_to_check = array(); |
---|
201 | $url = PEM_URL . '/api/get_version_list.php?category_id=12&format=php'; |
---|
202 | if ($this->fetchRemote($url, $result) and $pem_versions = @unserialize($result)) |
---|
203 | { |
---|
204 | if (!preg_match('/^\d+\.\d+\.\d+/', $version)) |
---|
205 | { |
---|
206 | $version = $pem_versions[0]['name']; |
---|
207 | } |
---|
208 | $branch = substr($version, 0, strrpos($version, '.')); |
---|
209 | foreach ($pem_versions as $pem_version) |
---|
210 | { |
---|
211 | if (strpos($pem_version['name'], $branch) === 0) |
---|
212 | { |
---|
213 | $versions_to_check[] = $pem_version['id']; |
---|
214 | } |
---|
215 | } |
---|
216 | } |
---|
217 | |
---|
218 | // Retrieve PEM template infos |
---|
219 | $url = PEM_URL . '/api/get_revision_list.php?format=php&last_revision_only=true'; |
---|
220 | $url .= '&version=' . implode(',', $versions_to_check); |
---|
221 | //$url .= '&lang=' . substr($user['language'], 0, 2); |
---|
222 | $url .= '&extension_include='.$eid; |
---|
223 | $this->fetchRemote($url, $result); |
---|
224 | $pem_res = @unserialize($result); |
---|
225 | foreach($pem_res as $pem_floOS) |
---|
226 | { |
---|
227 | if (!is_array($pem_floOS)) |
---|
228 | { |
---|
229 | $template->assign( |
---|
230 | array( |
---|
231 | 'erreur' => 'erreur url : '.$url, |
---|
232 | ) |
---|
233 | ); |
---|
234 | } |
---|
235 | if (!$this->floOS_version_compare($v_local, $pem_floOS['revision_name'])) |
---|
236 | { |
---|
237 | return true; |
---|
238 | } |
---|
239 | else |
---|
240 | { |
---|
241 | return false; |
---|
242 | } |
---|
243 | } |
---|
244 | } |
---|
245 | function display($names) |
---|
246 | { |
---|
247 | if (!is_array($names)) |
---|
248 | { |
---|
249 | global $template; |
---|
250 | $template->assign( |
---|
251 | array( |
---|
252 | 'erreur' => 'erreur get session var not array', |
---|
253 | ) |
---|
254 | ); |
---|
255 | } |
---|
256 | else |
---|
257 | { |
---|
258 | global $template, $user; |
---|
259 | load_language('template.lang', PHPWG_ROOT_PATH.'template/floOS/tools/'); |
---|
260 | $r_names=$names; |
---|
261 | foreach($names as $name => $version) |
---|
262 | { |
---|
263 | if ($name=='floOS') |
---|
264 | { |
---|
265 | include(PHPWG_ROOT_PATH.'template/floOS/tools/version.conf.php'); |
---|
266 | if ($this->floOS_version_compare($version, $floOS_conf['version'])) |
---|
267 | { |
---|
268 | $template->append('header_notes', l10n('floOS_update_needed')); |
---|
269 | } |
---|
270 | else |
---|
271 | { |
---|
272 | $p=array_search($name,array_keys($r_names)); |
---|
273 | array_splice ($r_names,$p,1); |
---|
274 | } |
---|
275 | |
---|
276 | } |
---|
277 | else |
---|
278 | { |
---|
279 | if ( is_dir(PHPWG_ROOT_PATH.'template/floOS/theme/'.$name) and is_file(PHPWG_ROOT_PATH.'template/floOS/theme/'.$name.'/themeconf.inc.php') ) |
---|
280 | { |
---|
281 | include(PHPWG_ROOT_PATH.'template/floOS/theme/'.$name.'/themeconf.inc.php'); |
---|
282 | if ($this->floOS_version_compare($version, $themeconf['version'])) |
---|
283 | { |
---|
284 | $msg=l10n('theme_update_needed_1').$themeconf['theme'].l10n('theme_update_needed_2').$themeconf['eid'].l10n('theme_update_needed_3').$themeconf['theme'].l10n('theme_update_needed_4'); |
---|
285 | $template->append('header_notes', $msg); |
---|
286 | } |
---|
287 | else |
---|
288 | { |
---|
289 | $p=array_search($name,array_keys($r_names)); |
---|
290 | array_splice ($r_names,$p,1); |
---|
291 | } |
---|
292 | } |
---|
293 | } |
---|
294 | } |
---|
295 | }//else |
---|
296 | |
---|
297 | pwg_set_session_var('floOS_array_version',$r_names); |
---|
298 | } |
---|
299 | } |
---|
300 | ?> |
---|