Add 'subscribe' feature for groups, and config to manage

This commit is contained in:
Retro_Guy 2022-01-11 23:19:54 +00:00
parent d5869313b2
commit 74f7f09fb1
5 changed files with 111 additions and 31 deletions

View File

@ -12,7 +12,11 @@
$logfile=$logdir.'/newsportal.log'; $logfile=$logdir.'/newsportal.log';
$accessfile=$logdir.'/access.log'; $accessfile=$logdir.'/access.log';
throttle_hits(); throttle_hits();
if(isset($_COOKIE['mail_name'])) {
$user = strtolower($_COOKIE['mail_name']);
$userfile=$spooldir.'/'.$user.'-articleviews.dat';
$userdata = unserialize(file_get_contents($userfile));
}
// register parameters // register parameters
$id=$_REQUEST["id"]; $id=$_REQUEST["id"];
$group=_rawurldecode($_REQUEST["group"]); $group=_rawurldecode($_REQUEST["group"]);
@ -23,7 +27,7 @@
header("Location: $newurl"); header("Location: $newurl");
die(); die();
} }
if(strpos($id, '@') !== false) { if(strpos($id, '@') !== false) {
if($CONFIG['article_database'] == '1') { if($CONFIG['article_database'] == '1') {
$database = $spooldir.'/articles-overview.db3'; $database = $spooldir.'/articles-overview.db3';
@ -54,8 +58,12 @@
$location = $_SERVER['REQUEST_URI'].$_SERVER['REQUEST_STRING']; $location = $_SERVER['REQUEST_URI'].$_SERVER['REQUEST_STRING'];
$_SESSION['return_page'] = $location.'#'.$id; $_SESSION['return_page'] = $location.'#'.$id;
file_put_contents($accessfile, "\n".format_log_date()." ".$config_name." ".$group.":".$id, FILE_APPEND); file_put_contents($accessfile, "\n".format_log_date()." ".$config_name." ".$group.":".$id, FILE_APPEND);
if($user) {
$userdata[$group] = time();
file_put_contents($userfile, serialize($userdata));
}
if(isset($frames_on) && $frames_on === true) { if(isset($frames_on) && $frames_on === true) {
?> ?>
<script> <script>

View File

@ -569,7 +569,10 @@ function groups_show($gruppen) {
$acttype="keins"; $acttype="keins";
echo '<table class="np_groups_table" cellspacing="0"><tr class="np_thread_head"><td width="45px" class="np_thread_head">'; echo '<table class="np_groups_table" cellspacing="0"><tr class="np_thread_head"><td width="45px" class="np_thread_head">';
echo 'Latest</td><td style="text-align: center;">Newsgroup</td><td width="8%" class="np_thread_head">Messages</td><td width="20%" class="np_thread_head" >Last Message</td></tr>'; echo 'Latest</td><td style="text-align: center;">Newsgroup</td><td width="8%" class="np_thread_head">Messages</td><td width="20%" class="np_thread_head" >Last Message</td></tr>';
$subs = array();
$nonsubs = array();
for($i = 0 ; $i < $c ; $i++) { for($i = 0 ; $i < $c ; $i++) {
unset($groupdisplay);
$g = $gruppen[$i]; $g = $gruppen[$i];
if(isset($g->text)) { if(isset($g->text)) {
if($acttype!="text") { if($acttype!="text") {
@ -579,41 +582,50 @@ function groups_show($gruppen) {
if($acttype!="group") { if($acttype!="group") {
$acttype="group"; $acttype="group";
} }
$user = null;
if(isset($_COOKIE['mail_name'])) {
$user = strtolower($_COOKIE['mail_name']);
$userfile=$spooldir.'/'.$user.'-articleviews.dat';
$userdata = unserialize(file_get_contents($userfile));
}
/* Display group name and description */ /* Display group name and description */
$lineclass="np_thread_line".(($i%2)+1); if(isset($userdata[$g->name])) {
$lineclass="np_thread_line2";
echo '<tr class="'.$lineclass.'"><td style="text-align: center;" class="'.$lineclass.'">'; } else {
echo '<a href="overboard.php?thisgroup='._rawurlencode($g->name).'">'; $lineclass="np_thread_line1";
}
$groupdisplay = '<tr class="'.$lineclass.'"><td style="text-align: center;" class="'.$lineclass.'">';
$groupdisplay.='<a href="overboard.php?thisgroup='._rawurlencode($g->name).'">';
if (file_exists('../common/themes/'.$_SESSION['theme'].'/images/latest.png')) { if (file_exists('../common/themes/'.$_SESSION['theme'].'/images/latest.png')) {
$latest_image='../common/themes/'.$_SESSION['theme'].'/images/latest.png'; $latest_image='../common/themes/'.$_SESSION['theme'].'/images/latest.png';
} else { } else {
$latest_image='../common/images/latest.png'; $latest_image='../common/images/latest.png';
} }
echo '<img src="'.$latest_image.'">'; $groupdisplay.='<img src="'.$latest_image.'">';
echo '</a>'; $groupdisplay.='</a>';
echo '</td>'; $groupdisplay.='</td>';
echo '<td class="'.$lineclass.'">'; $groupdisplay.='<td class="'.$lineclass.'">';
echo '<span class="np_group_line_text">'; $groupdisplay.='<span class="np_group_line_text">';
echo '<a '; $groupdisplay.='<a ';
echo 'target="'.$frame['content'].'" '; $groupdisplay.='target="'.$frame['content'].'" ';
echo 'href="'.$file_thread.'?group='._rawurlencode($g->name).'"><span class="np_group_line_text">'.group_display_name($g->name)."</span></a>\n"; $groupdisplay.='href="'.$file_thread.'?group='._rawurlencode($g->name).'"><span class="np_group_line_text">'.group_display_name($g->name)."</span></a>\n";
if($g->description!="-") if($g->description!="-")
echo '</span><br><p class="np_group_desc">'.$g->description.'</p>'; $groupdisplay.='</span><br><p class="np_group_desc">'.$g->description.'</p>';
/* Display article count */ /* Display article count */
echo '</td><td class="'.$lineclass.'">'; $groupdisplay.='</td><td class="'.$lineclass.'">';
if($gl_age) if($gl_age)
$datecolor=thread_format_date_color($g->age); $datecolor=thread_format_date_color($g->age);
echo '<small>'; $groupdisplay.='<small>';
if($datecolor!="") if($datecolor!="")
echo '<font color="'.$datecolor.'">'.$g->count.'</font>'; $groupdisplay.='<font color="'.$datecolor.'">'.$g->count.'</font>';
else else
echo $g->count; $groupdisplay.=$g->count;
echo '</small>'; $groupdisplay.='</small>';
/* Display latest article info */ /* Display latest article info */
echo '</td><td class="'.$lineclass.'"><div class="np_last_posted_date">'; $groupdisplay.='</td><td class="'.$lineclass.'"><div class="np_last_posted_date">';
$filename = $spooldir."/".$g->name."-lastarticleinfo.dat"; $filename = $spooldir."/".$g->name."-lastarticleinfo.dat";
if($file=@fopen($filename,"r")) { if($file=@fopen($filename,"r")) {
$lastarticleinfo=unserialize(fread($file,filesize($filename))); $lastarticleinfo=unserialize(fread($file,filesize($filename)));
@ -654,14 +666,30 @@ function groups_show($gruppen) {
} }
} }
} }
echo get_date_interval(date("D, j M Y H:i T",$lastarticleinfo->date)); if(isset($userdata[$g->name])) {
echo '<table><tr><td>'; if($userdata[$g->name] < $lastarticleinfo->date) {
echo '<font class="np_last_posted_date">by: '; $groupdisplay.='(<b>new</b>) ';
echo create_name_link(mb_decode_mimeheader($lastarticleinfo->name)); }
echo '</td></tr></table>'; }
$groupdisplay.=get_date_interval(date("D, j M Y H:i T",$lastarticleinfo->date));
$groupdisplay.='<table><tr><td>';
$groupdisplay.='<font class="np_last_posted_date">by: ';
$groupdisplay.=create_name_link(mb_decode_mimeheader($lastarticleinfo->name));
$groupdisplay.='</td></tr></table>';
} }
echo "\n"; $groupdisplay.="\n";
flush(); flush();
if(isset($userdata[$g->name])) {
$subs[] = $groupdisplay;
} else {
$nonsubs[] = $groupdisplay;
}
} // END
foreach($subs as $sub) {
echo $sub;
}
foreach($nonsubs as $nonsub) {
echo $nonsub;
} }
echo "</td></div></table>\n"; echo "</td></div></table>\n";
} }

View File

@ -28,7 +28,11 @@
include "$file_newsportal"; include "$file_newsportal";
throttle_hits(); throttle_hits();
if(isset($_COOKIE['mail_name'])) {
$user = strtolower($_COOKIE['mail_name']);
$userfile=$spooldir.'/'.$user.'-articleviews.dat';
$userdata = unserialize(file_get_contents($userfile));
}
if(isset($frames_on) && $frames_on === true) { if(isset($frames_on) && $frames_on === true) {
?> ?>
<script> <script>
@ -78,6 +82,10 @@ if (isset($_GET['thisgroup'])) {
$grouplist = array(); $grouplist = array();
$grouplist[0] = _rawurldecode(_rawurldecode($_GET['thisgroup'])); $grouplist[0] = _rawurldecode(_rawurldecode($_GET['thisgroup']));
$cachefile=$spooldir."/".$grouplist[0]."-overboard.dat"; $cachefile=$spooldir."/".$grouplist[0]."-overboard.dat";
if($user) {
$userdata[$grouplist[0]] = time();
file_put_contents($userfile, serialize($userdata));
}
} else { } else {
$grouplist = file($groupconfig, FILE_IGNORE_NEW_LINES); $grouplist = file($groupconfig, FILE_IGNORE_NEW_LINES);
} }

View File

@ -26,6 +26,11 @@ if(isset($_REQUEST["last"]))
die(); die();
} }
if(isset($_COOKIE['mail_name'])) {
$user = strtolower($_COOKIE['mail_name']);
$userfile=$spooldir.'/'.$user.'-articleviews.dat';
$userdata = unserialize(file_get_contents($userfile));
}
$thread_show["latest"]=true; $thread_show["latest"]=true;
$title.= ' - '.$group; $title.= ' - '.$group;
include "head.inc"; include "head.inc";
@ -50,7 +55,11 @@ if(isset($frames_on) && $frames_on === true) {
</script> </script>
<?php <?php
} }
if($user) {
$userdata[$group] = time();
file_put_contents($userfile, serialize($userdata));
}
$_SESSION['return_page'] = $_SERVER['REQUEST_URI'].$_SERVER['REQUEST_STRING']; $_SESSION['return_page'] = $_SERVER['REQUEST_URI'].$_SERVER['REQUEST_STRING'];
echo '<a name="top"></a>'; echo '<a name="top"></a>';

View File

@ -117,6 +117,9 @@ echo '</table>';
$user = strtolower($_POST['username']); $user = strtolower($_POST['username']);
$_SESSION['username'] = $user; $_SESSION['username'] = $user;
unset($user_config); unset($user_config);
$userfile=$spooldir.'/'.$user.'-articleviews.dat';
$userdata = unserialize(file_get_contents($userfile));
ksort($userdata);
// Apply Config // Apply Config
if(isset($_POST['command']) && $_POST['command'] == 'SaveConfig') { if(isset($_POST['command']) && $_POST['command'] == 'SaveConfig') {
@ -126,6 +129,20 @@ echo '</table>';
$user_config['theme'] = $_POST['listbox']; $user_config['theme'] = $_POST['listbox'];
file_put_contents($config_dir.'/userconfig/'.$user.'.config', serialize($user_config)); file_put_contents($config_dir.'/userconfig/'.$user.'.config', serialize($user_config));
$_SESSION['theme'] = $user_config['theme']; $_SESSION['theme'] = $user_config['theme'];
$mysubs = explode("\n", $_POST['subscribed']);
foreach($mysubs as $sub) {
if(trim($sub) == '') {
continue;
}
$sub = trim($sub);
if(!isset($userdata[$sub])) {
$userdata[$sub] = 0;
}
$newsubs[$sub] = $userdata[$sub];
}
file_put_contents($spooldir.'/'.$user.'-articleviews.dat', serialize($newsubs));
$userdata = unserialize(file_get_contents($userfile));
ksort($userdata);
echo 'Configuration Saved for '.$_POST[username]; echo 'Configuration Saved for '.$_POST[username];
} else { } else {
$user_config = unserialize(file_get_contents($config_dir.'/userconfig/'.$user.'.config')); $user_config = unserialize(file_get_contents($config_dir.'/userconfig/'.$user.'.config'));
@ -144,6 +161,7 @@ echo '</table>';
} }
} }
sort($themes); sort($themes);
// Show Config // Show Config
echo '<hr><h1 class="np_thread_headline">Configuration:</h1>'; echo '<hr><h1 class="np_thread_headline">Configuration:</h1>';
echo '<table cellspacing="0" width="100%" class="np_results_table">'; echo '<table cellspacing="0" width="100%" class="np_results_table">';
@ -174,6 +192,14 @@ echo '</table>';
echo '</select>'; echo '</select>';
echo '</td>'; echo '</td>';
echo '</tr>'; echo '</tr>';
// Subscriptions
echo '<td class="np_result_line1" style="word-wrap:break-word";>Subscribed:</td>';
echo '</tr><tr><td class="np_result_line1" style="word-wrap:break-word";><textarea class="configuration" id="subscribed" name="subscribed" rows="10" cols="40">';
foreach($userdata as $key => $value) {
echo $key."\n";
}
echo '</textarea></td>';
echo '</tr>';
/* /*
// Timezone // Timezone
echo '<td class="np_result_line1" style="word-wrap:break-word";>Timezone offset (+/- hours from UTC):</td>'; echo '<td class="np_result_line1" style="word-wrap:break-word";>Timezone offset (+/- hours from UTC):</td>';
@ -182,6 +208,7 @@ echo '</table>';
*/ */
echo '<td class="np_result_line2" style="word-wrap:break-word";>'; echo '<td class="np_result_line2" style="word-wrap:break-word";>';
echo '<button class="np_button_link" type="submit">Save Configuration</button>'; echo '<button class="np_button_link" type="submit">Save Configuration</button>';
echo '<a href="'.$_SERVER['PHP_SELF'].'">Cancel</a>';
echo '</td></tr>'; echo '</td></tr>';
echo '<input name="command" type="hidden" id="command" value="SaveConfig" readonly="readonly">'; echo '<input name="command" type="hidden" id="command" value="SaveConfig" readonly="readonly">';
echo '</form>'; echo '</form>';