-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.php
52 lines (41 loc) · 1.69 KB
/
index.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
<?php
mb_http_output('UTF-8');
$feedXML = file_get_contents("https://www.nepalmonitor.org/index.php/feed");
$categoryHashtags = json_decode(file_get_contents("category-hashtags.json"), true);
$xml=simplexml_load_string($feedXML) or die("There's an error in our Twitter feed system. We're working on it. Until then you can view new reports directly at nepalmonitor.org");
$arr = array(' ');
foreach ($xml->xpath('//item') as $item) {
$r = '...#Nepal';
foreach($item->children() as $category){
if($category->getName() == 'category'){
$categoryString = (string)$category;
if($categoryHashtags[$categoryString]){
if(strlen($r.' #'.$categoryHashtags[$categoryString])<=48)
$r .= ' #'.$categoryHashtags[$categoryString];
}else{
$t = ' #'.(preg_split('/ |\//', $categoryString)[0]);
if(strlen($r.$t)<=38)
$r .= $t;
}
}
}
array_push($arr, $r);
}
function str_replace_nth($search, $replace, $subject, $nth)
{
$found = preg_match_all('/'.$search.'/u', $subject, $matches, PREG_OFFSET_CAPTURE);
if (false !== $found && $found > $nth) {
return substr_replace($subject, $replace, $matches[0][$nth][1], strlen($search));
}
return $subject;
}
$feedXML=htmlspecialchars($feedXML);
$feedXML = preg_replace('/<title>(.{1,70})(.+)<\/title>/u', "<title>$1</title>", $feedXML);
foreach($arr as $m=>$s){
$feedXML = str_replace_nth('<\/title>', $arr[$m].'</title>', $feedXML, $m);
}
$report = fopen("feed.xml", w);
fwrite($report, htmlspecialchars_decode($feedXML));
fclose($report);
header('Location: feed.xml');
?>