Add RSS pull and post feature

This commit is contained in:
Retro_Guy 2021-12-02 04:02:31 +00:00
parent 6609288a2b
commit db7c851891
8 changed files with 111 additions and 5 deletions

View File

@ -74,6 +74,7 @@ mkdir -p $spoolpath
echo "done"
echo -n "$configpath..."
mkdir -p $configpath
mkdir -p $configpath/rss
mkdir -p $configpath/users
mkdir -p $configpath/userconfig
echo "done"

View File

@ -73,6 +73,7 @@ mkdir -p $spoolpath
echo "done"
echo -n "$configpath..."
mkdir -p $configpath
mkdir -p $configpath/rss
mkdir -p $configpath/users
mkdir -p $configpath/userconfig
echo "done"

View File

@ -194,7 +194,7 @@ function check_rate_limit($name,$set=0,$gettime=0) {
* $ref: The references of the article
* $body: The article itself
*/
function message_post($subject,$from,$newsgroups,$ref,$body,$encryptthis,$encryptto,$authname) {
function message_post($subject,$from,$newsgroups,$ref,$body,$encryptthis=null,$encryptto=null,$authname=null,$followupto=null) {
global $server,$port,$send_poster_host,$text_error,$CONFIG;
global $www_charset,$config_dir,$spooldir;
global $msgid_generate,$msgid_fqdn;
@ -259,6 +259,9 @@ function message_post($subject,$from,$newsgroups,$ref,$body,$encryptthis,$encryp
}
}
fputs($ns,'From: '.$from."\r\n");
if($followupto !== null) {
fputs($ns,'Followup-To: '.$followupto."\r\n");
}
fputs($ns,'Newsgroups: '.$newsgroups."\r\n");
$sitekey=password_hash($CONFIG['thissitekey'].$msgid, PASSWORD_DEFAULT);
fputs($ns,'X-Rslight-Site: '.$sitekey."\r\n");

View File

@ -260,7 +260,11 @@ if ($type=="post") {
}
}
// echo '<p><a href="'.$file_thread.'?group='.urlencode($returngroup[0]).'">'.$text_post["button_back"].'</a> '.$text_post["button_back2"].' '.group_display_name($returngroup[0]).'</p>';
echo '<p><a href="'.$_SESSION['return_page'].'">Back to Previous Page</a></p>';
if(isset($_REQUEST['returngroup']) && $_REQUEST['returngroup'] !== '') {
echo '<p><a href="'.$file_thread.'?group='.$_REQUEST['returngroup'].'">Your post will appear in '.group_display_name($_REQUEST['returngroup']).'</a></p>';
} else {
echo '<p><a href="'.$_SESSION['return_page'].'">Back to Previous Page</a></p>';
}
} else {
// article not accepted by the newsserver
$type="retry";
@ -342,7 +346,6 @@ if ($newsgroups == "") {
} else {
// show post form
$fieldencrypt=md5(rand(1,10000000));
echo '<h1 class="np_post_headline">'.$text_post["group_head"].group_display_name($newsgroups)
.$text_post["group_tail"].'</h1>';
@ -438,16 +441,16 @@ function quoten() {
echo captcha::form($text_post["captchainfo1"],$text_post["captchainfo2"]);
echo '</td></tr>';
} ?>
</table>
</div>
<input type="hidden" name="type" value="post">
<input type="hidden" name="newsgroups" value="<?php echo htmlspecialchars($newsgroups); ?>">
<input type="hidden" name="references" value="<?php echo htmlentities($references); ?>">
<input type="hidden" name="group" value="<?php echo htmlspecialchars($newsgroups); ?>">
<input type="hidden" name="returngroup" value="<?php echo htmlspecialchars($head->followup); ?>">
<input type="hidden" name="fielddecrypt" value="<?php echo htmlspecialchars($fieldencrypt);?>">
</form>
<?php } } ?>

View File

@ -74,6 +74,9 @@ foreach($menulist as $menu) {
exec($CONFIG['php_exec']." ".$config_dir."/scripts/expire.php");
echo "Expired articles\n";
}
# Run RSS Feeds
exec($CONFIG['php_exec']." ".$config_dir."/scripts/rss-feeds.php");
echo "RSS Feeds updated\n";
# Rotate log files
log_rotate();
echo "Log files rotated\n";

View File

@ -0,0 +1,93 @@
#!/usr/local/bin/php
<?php
include "config.inc.php";
include "newsportal.php";
$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']);
$xml = simplexml_load_string($xmlData);
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";
$body.=trim($item->{$RSS['content']});
$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')) {
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);
}
?>

View File

@ -0,0 +1 @@
../rocksolid/lib

View File

@ -0,0 +1 @@
../rocksolid/post.php