Pull articles directly from db or spool if exist, else request from server

This commit is contained in:
Retro_Guy 2021-01-22 18:04:37 -07:00
parent aef9df41a8
commit 77350f50d6
1 changed files with 22 additions and 14 deletions

View File

@ -180,7 +180,8 @@ function message_parse($rawmessage) {
* attachment. * attachment.
*/ */
function message_read($id,$bodynum=0,$group="") { function message_read($id,$bodynum=0,$group="") {
global $cache_articles,$spooldir,$spoolpath,$text_error,$ns; global $CONFIG,$config_name,$cache_articles,$spooldir,$spoolpath,$logdir,$text_error,$ns;
$logfile = $logdir.'/newsportal.log';
if (!testGroup($group)) { if (!testGroup($group)) {
echo $text_error["read_access_denied"]; echo $text_error["read_access_denied"];
return; return;
@ -218,20 +219,27 @@ function message_read($id,$bodynum=0,$group="") {
((!isset($message->body[$bodynum])) && ((!isset($message->body[$bodynum])) &&
($bodynum != -1))) { ($bodynum != -1))) {
// Pull article from spool if exists, else from server // Pull article from spool if exists, else from server
$articlepath = $spoolpath.preg_replace('/\./', '/', $group)."/".$id; unset($rawmessage);
if (file_exists($articlepath)) { if($CONFIG['article_database'] == '1') {
$rawmessage_fh = fopen($articlepath, "r"); $rawmessage = np_get_db_article($id, $group, 1);
$rawmessage=array(); } else {
$line=rtrim(fgets($rawmessage_fh), PHP_EOL); $articlepath = $spoolpath.preg_replace('/\./', '/', $group)."/".$id;
while(!feof($rawmessage_fh)) { if (file_exists($articlepath)) {
if(strcmp($line,".") == 0) { $rawmessage_fh = fopen($articlepath, "r");
break; $rawmessage=array();
$line=rtrim(fgets($rawmessage_fh), PHP_EOL);
while(!feof($rawmessage_fh)) {
if(strcmp($line,".") == 0) {
break;
}
$rawmessage[]=$line;
$line=rtrim(fgets($rawmessage_fh), PHP_EOL);
} }
$rawmessage[]=$line; fclose($rawmessage_fh);
$line=rtrim(fgets($rawmessage_fh), PHP_EOL); }
} }
fclose($rawmessage_fh); if(!isset($rawmessage)) {
} else { file_put_contents($logfile, "\n".format_log_date()." ".$config_name." DEBUG: Requesting: ".$group.":".$id." from server", FILE_APPEND);
if (!isset($ns)) { if (!isset($ns)) {
$ns=nntp_open(); $ns=nntp_open();
} }