blob: f429241fe67dcda2dd58c3d375c1db5fcf231723 (
plain)
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
|
<?php
$config = array(
'type' => 'xpath',
'xpath' => 'div[@class="meldung_wrapper"]',
);
// http://www.heise.de/newsticker/heise-atom.xml
$article = array(
'link' => 'http://www.heise.de/newsticker/meldung/Fruehjahrspatches-Microsoft-9-Adobe-3-1838175.html/from/atom10',
'content' => 'This is the feed content',
'plugin_data' => '',
);
$doc = new DOMDocument();
$html = file_get_contents($article['link']);
// BEGIN --- New code
$headers = $http_response_header;
$content_type = false;
foreach ($headers as $h) {
if (substr(strtolower($h), 0, 13) == 'content-type:') {
$content_type = substr($h, 14);
// don't break here to find LATEST (if redirected) entry
}
}
$charset = false;
if ($content_type) {
preg_match('/charset=(\S+)/', $content_type, $matches);
if (isset($matches[1]) && !empty($matches[1])) $charset = $matches[1];
}
// END --- New code
echo 'CHARSET: ' . $charset . PHP_EOL;
$doc->loadHTML('<?xml encoding="' . $charset . '">' . $html);
echo 'ENCODING: ' . $doc->encoding . PHP_EOL;
if ($doc) {
$basenode = false;
$xpath = new DOMXPath($doc);
$entries = $xpath->query('(//'.$config['xpath'].')'); // find main DIV according to config
var_dump($entries);
if ($entries->length > 0) $basenode = $entries->item(0);
if ($basenode) {
$article['content'] = $doc->saveXML($basenode);
$article['plugin_data'] = "feedmod,$owner_uid:" . $article['plugin_data'];
}
}
print_r($article);
|