2021-12-02 05:02:31 +01:00
|
|
|
#!/usr/local/bin/php
|
|
|
|
<?php
|
2021-12-03 03:27:18 +01:00
|
|
|
chdir('../rocksolid/');
|
2021-12-02 05:02:31 +01:00
|
|
|
include "config.inc.php";
|
|
|
|
include "newsportal.php";
|
|
|
|
|
2021-12-08 04:35:10 +01:00
|
|
|
$maxlen = 500;
|
2021-12-02 05:02:31 +01:00
|
|
|
$rssdir = $config_dir.'/rss/';
|
|
|
|
$rssfiles = array();
|
|
|
|
if(isset($argv[1])) {
|
|
|
|
$rssfiles[0] = $argv[1];
|
|
|
|
} else {
|
|
|
|
$rssfiles = array_diff(scandir($rssdir), array('..', '.'));
|
|
|
|
}
|
|
|
|
foreach($rssfiles as $rssfile) {
|
|
|
|
if(!is_file($config_dir.'/rss/'.$rssfile)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$body = '';
|
|
|
|
unset($RSS);
|
|
|
|
$RSS = get_rss_config($config_dir.'/rss/'.$rssfile);
|
|
|
|
if($RSS['enable'] !== '1') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(filemtime($spooldir.'/'.$rssfile.'-rss-timer') + $RSS['timer'] > time()) {
|
|
|
|
if(!is_file($rssdir.'/debug')) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$xmlData = file_get_contents($RSS['url']);
|
2021-12-08 04:35:10 +01:00
|
|
|
$xml = simplexml_load_string($xmlData, 'SimpleXMLElement', LIBXML_NOCDATA);
|
2021-12-02 05:02:31 +01:00
|
|
|
if($RSS['root'] != '') {
|
|
|
|
$xmlstart = $xml->{$RSS['root']};
|
|
|
|
} else {
|
|
|
|
$xmlstart = $xml;
|
|
|
|
}
|
|
|
|
foreach($xmlstart->{$RSS['item']} as $item)
|
|
|
|
{
|
|
|
|
if(trim($item->{$RSS['link']}) == '') {
|
|
|
|
$item->{$RSS['link']} = $item->{$RSS['link']}[href];
|
|
|
|
} else {
|
|
|
|
$item->{$RSS['link']} = $item->{$RSS['link']};
|
|
|
|
}
|
|
|
|
$body.=$item->{$RSS['title']}."\n";
|
|
|
|
if(isset($RSS['urlprefix']) && ($RSS['urlprefix'] !== '')) {
|
|
|
|
$url = $RSS['urlprefix'].$item->{$RSS['link']};
|
|
|
|
} else {
|
|
|
|
$url = $item->{$RSS['link']};
|
|
|
|
}
|
|
|
|
if(isset($RSS['urlprefixalt']) && ($RSS['urlprefixalt'] !== '')) {
|
|
|
|
$urlalt = $RSS['urlprefixalt'].$item->{$RSS['link']};
|
|
|
|
} else {
|
|
|
|
$urlalt = '';
|
|
|
|
}
|
|
|
|
if(substr($url,0,4) !== "http") {
|
|
|
|
$urlprefix = explode('/', $RSS['url']);
|
|
|
|
$url = $urlprefix[0].'/'.$urlprefix[1].'/'.$urlprefix[2].$item->{$RSS['link']};
|
|
|
|
}
|
|
|
|
$body.=$url."\n";
|
|
|
|
if($urlalt !== '') {
|
|
|
|
$body.=$urlalt."\n";
|
|
|
|
}
|
|
|
|
if(isset($RSS['date_namespaceuri']) && ($RSS['date_namespaceuri'] !== '')) {
|
|
|
|
$dc_date = $item->children($RSS['date_namespaceuri']);
|
|
|
|
$body.=date("F j, Y, g:i A", strtotime($dc_date));
|
|
|
|
} else {
|
|
|
|
$body.=date("F j, Y, g:i A", strtotime($item->{$RSS['date']}));
|
|
|
|
}
|
|
|
|
$body.="\n";
|
2021-12-08 04:35:10 +01:00
|
|
|
if(strlen($item->{$RSS['content']}) > $maxlen) {
|
|
|
|
$content=substr(trim(strip_tags($item->{$RSS['content']})),0,$maxlen);
|
|
|
|
$dots = '...';
|
|
|
|
} else {
|
|
|
|
$content=trim(strip_tags($item->{$RSS['content']}));
|
|
|
|
$dots = '';
|
|
|
|
}
|
|
|
|
$content = preg_replace('#\R+#', "\n", $content);
|
|
|
|
$body.=$content.$dots;
|
2021-12-02 05:02:31 +01:00
|
|
|
$body.="\n--------------------\n";
|
|
|
|
}
|
|
|
|
if(strpos($RSS['postfrom'], '@') === false) {
|
|
|
|
$RSS['postfrom'] = $RSS['postfrom'].$CONFIG['email_tail'];
|
|
|
|
}
|
|
|
|
if(isset($RSS['followupto']) && ($RSS['followupto'] !== '')) {
|
|
|
|
$followupto = $RSS['followupto'];
|
|
|
|
} else {
|
|
|
|
$followupto = null;
|
|
|
|
}
|
|
|
|
$body = strip_tags($body);
|
|
|
|
|
|
|
|
if(is_file($rssdir.'/debug')) {
|
2021-12-08 04:35:10 +01:00
|
|
|
print_r($xml);
|
2021-12-02 05:02:31 +01:00
|
|
|
echo $body;
|
|
|
|
} else {
|
|
|
|
echo message_post($RSS['message_subject'], $RSS['postfrom'], $RSS['newsgroup'], null, $body, null, null, null, $followupto)."\n";
|
|
|
|
touch($spooldir.'/'.$rssfile.'-rss-timer');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_rss_config($rssfile) {
|
|
|
|
$RSS = include($rssfile);
|
|
|
|
return($RSS);
|
|
|
|
}
|
|
|
|
?>
|