Rev 2 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 5 | ||
---|---|---|---|
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * Google GetCache |
4 | * Google GetCache |
5 | * Copyright 2015 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2015 Daniel Marschall, ViaThinkSoft |
6 | * Version 2015-06-26 |
6 | * Version 2015-06-26 |
7 | * |
7 | * |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
9 | * you may not use this file except in compliance with the License. |
9 | * you may not use this file except in compliance with the License. |
10 | * You may obtain a copy of the License at |
10 | * You may obtain a copy of the License at |
11 | * |
11 | * |
12 | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | * http://www.apache.org/licenses/LICENSE-2.0 |
13 | * |
13 | * |
14 | * Unless required by applicable law or agreed to in writing, software |
14 | * Unless required by applicable law or agreed to in writing, software |
15 | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | * distributed under the License is distributed on an "AS IS" BASIS, |
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17 | * See the License for the specific language governing permissions and |
17 | * See the License for the specific language governing permissions and |
18 | * limitations under the License. |
18 | * limitations under the License. |
19 | */ |
19 | */ |
20 | 20 | ||
21 | function google_getcache($url) { |
21 | function google_getcache($url) { |
22 | $options = array( |
22 | $options = array( |
23 | 'http'=>array( |
23 | 'http'=>array( |
24 | 'method'=>"GET", |
24 | 'method'=>"GET", |
25 | 'header'=>"Accept-language: en\r\n" . |
25 | 'header'=>"Accept-language: en\r\n" . |
26 | "Cookie: foo=bar\r\n" . // check function.stream-context-create on php.net |
26 | "Cookie: foo=bar\r\n" . // check function.stream-context-create on php.net |
27 | "User-Agent: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" |
27 | "User-Agent: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" |
28 | ) |
28 | ) |
29 | ); |
29 | ); |
30 | 30 | ||
31 | $context = stream_context_create($options); |
31 | $context = stream_context_create($options); |
32 | 32 | ||
33 | $url = 'https://www.google.de/search?q='.urlencode($url); |
33 | $url = 'https://www.google.de/search?q='.urlencode($url); |
34 | $cont = file_get_contents($url, false, $context); |
34 | $cont = file_get_contents($url, false, $context); |
35 | preg_match_all('@(http://webcache.googleusercontent.com/.+)"@ismU', $cont, $m); |
35 | preg_match_all('@(http://webcache.googleusercontent.com/.+)"@ismU', $cont, $m); |
36 | if (!isset($m[1][0])) return false; |
36 | if (!isset($m[1][0])) return false; |
37 | $url = urldecode($m[1][0]); |
37 | $url = urldecode($m[1][0]); |
38 | return file_get_contents($url, false, $context); |
38 | return file_get_contents($url, false, $context); |
39 | } |
39 | } |
40 | 40 |