Topic: New message mod++ :)
So, after my unsuccessful try to resurrect improved new message mod, I have rewritten phorum.org "new marking" system.
Its not very pretty, but it works There may be some mistakes, so be careful
go to file lang/en_common.php
find line:
'Mark all as read' => 'Mark all forums as read',
replace with:
'Mark all as read' => 'Mark forum as read',
go to file include/functions.php
add:
function explode_haveread($var){
global $haveread;
$haveread[$var]=true;
}
go to file idex.php
find :
if (!$cookie['is_guest'] &&($cur_forum['last_post'] > $cur_user['last_post']))
{
if ($cur_user['show_img'] == '1')
$icon = '<img src="img/'.$cur_user['style'].'_new.png" w
else
$icon = '<span class="puntext"><b>?</b></span>';
}
else
$icon = ' ';
delete all this, and add then:
$f_id = $cur_forum['fid'];
$forum_id = $f_id;
$new_cookie="pun-new-$forum_id";
$haveread_cookie="pun-haveread-$forum_id";
$res = $db->query('Select last_post_id as f_maxid FROM '.$db->prefix.'forums WHERE id='.$f_id.'');
$f_maxid = $db->result($res,0);
if(!IsSet($$new_cookie)){
$$new_cookie='0';
}
$use_haveread=false;
if(IsSet($$haveread_cookie)) {
$arr=explode(".", $$haveread_cookie);
$old_message=reset($arr);
array_walk($arr, "explode_haveread");
$use_haveread=true;
}
else{
$old_message=$$new_cookie;
}
$isnew=false;
if($use_haveread){
if ($old_message<$f_maxid) {
if(!IsSet($haveread[$f_maxid])) {
$isnew=true;
}
}
}
elseif($old_message<$f_maxid){
$isnew=true;
}
if($isnew)
{
if (!$cookie['is_guest'])
{
if ($cur_user['show_img'] == '1')
$icon = '<img src="img/'.$cur_user['style'].'_new.png" w
else
$icon = '<span class="puntext"><b>?</b></span>';
}
else
$icon = '<img src="img/'.$pun_config['o_default_style'].'_new.png" width="16" height="16" alt="">';
}
else
$icon = ' ';
go to file misc.php
find line:
elseif ($action == 'markread')
{
....................
}
and replace whole elsif expression with:
elseif ($action == 'markread')
{
$forum_id = intval($_GET['fid']);
$new_cookie="pun-new-$forum_id";
$haveread_cookie="pun-haveread-$forum_id";
$res = $db->query('Select last_post_id as max_id FROM '.$db->prefix.'forums WHERE id='.$forum_id.'');
//$aryRow=$q->getrow();
$aryRow= $db->fetch_array($res);
if(isset($aryRow['max_id'])){
$max_id=$aryRow['max_id'];
$$new_cookie=$max_id;
SetCookie($new_cookie,$$new_cookie,time()+ 31536000);
SetCookie($haveread_cookie,$$new_cookie); //destroy session cookie
unset($$haveread_cookie);
}
redirect($_SERVER['HTTP_REFERER'], $lang_misc['Mark read redirect']);
}
go to file viewforum.php
find line:
<td class="punright" style="width: 19%; white-space: nowrap"><b><?php echo $post_link ?></b></td>
after it add:
<td><?php echo ' <b><a href="misc.php?action=markread&fid='.$id.'">'.$lang_common['Mark forum read'].'</b></a>' ?></td>
find:
if (!$cookie['is_guest'] && $cur_topic['last_post'] > $cur_user['last_visit'] && $cur_topic['moved_to'] == null)
{
if ($cur_user['show_img'] == '1')
$icon = '<img src="img/'.$cur_user['style'].'_new.png" width="16" height="16" alt="">';
else
$icon = '<span class="puntext"><b>?</b></span>';
$subject = '<b>'.$subject.'</b>';
//New posts in the topic
$subject_new_posts = '[ <a href="viewtopic.php?id='.$cur_topic['id'].'&action=new" title="'.$lang_common['New posts info'].'">'.$lang_common['New posts'].'</a> ]';
}
else
{
$icon = ' ';
$subject_new_posts = null;
}
replace whole this block with:
$forum_id = $id;
$new_cookie="pun-new-$forum_id";
$haveread_cookie="pun-haveread-$forum_id";
$t_id = $cur_topic['id'];
$res = $db->query('Select last_post_id as t_maxid FROM '.$db->prefix.'topics WHERE id='.$cur_topic['id'].'');
$t_maxid = $db->result($res,0);
if(!IsSet($$new_cookie)){
$$new_cookie='0';
}
$use_haveread=false;
if(IsSet($$haveread_cookie)) {
$arr=explode(".", $$haveread_cookie);
$old_message=reset($arr);
array_walk($arr, "explode_haveread");
$use_haveread=true;
}
else{
$old_message=$$new_cookie;
}
$isnew=false;
if($use_haveread){
if ($old_message<$t_maxid) {
if(!IsSet($haveread[$t_maxid])) {
$isnew=true;
}
}
}
elseif($old_message<$t_maxid){
$isnew=true;
}
if($isnew){
//New posts in the topic
$subject_new_posts = '[ <a href="viewtopic.php?id='.$cur_topic['id'].'&action=new" title="'.$lang_common['New posts info'].'"><font color=orange>New</font></a> ]';
}
else{
$subject_new_posts = null;}
go to file viewtopic.php
find:
else if (isset($_GET['action']) && $_GET['action'] == 'new' && !$cookie['is_guest'])
{
$result = $db->query('SELECT MIN(id) FROM '.$db->prefix.'posts WHERE topic_id='.$id.' AND posted >'.$cur_user['last_visitonline']) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
$first_new_post_id = $db->result($result, 0);
replace whole block with:
else if (isset($_GET['action']) && $_GET['action'] == 'new')
{
$res = $db->query('Select id from '.$db->prefix.'posts where topic_id='.$id.' ORDER BY id');
$rec = $db->fetch_row($res);
While($rec){
$msgarr[]=$rec[0];
$rec = $db->fetch_row($res);
}
$res = $db->query('Select forum_id from '.$db->prefix.'topics where topic_id='.$id.'');
$forum_id = $db->result($res,0);
$new_cookie="pun-new-$forum_id";
$haveread_cookie="pun-haveread-$forum_id";
$arr=explode(".", $$haveread_cookie);
function newmsg($a, $b) {
$al = sizeof($a);
$bl = sizeof($b);
sort($a);
if ($b[$bl-1]<$a[0]) return $b[$bl-1];
$i = 0; $j = 0;
while(1) {
if ($a[$i] < $b[$j]) {
$i++;
if ($i == $al) return $b[$j];
} else if($a[$i] == $b[$j]) {
$j++;
if ($j == $bl) return $b[$bl-1];
} else {
return $b[$j];
}
}
}
$first_new_post_id = newmsg($arr, $msgarr);
find line:
$footer_style = 'topic';
before add:
$new_cookie="pun-new-$forum_id";
$haveread_cookie="pun-haveread-$forum_id";
if(!IsSet($$new_cookie)){
$$new_cookie='0';
}
$use_haveread=false;
if(IsSet($$haveread_cookie)) {
$arr=explode(".", $$haveread_cookie);
$old_message=@reset($arr);
array_walk($arr, "explode_haveread");
$use_haveread=true;
}
else{
$old_message=$$new_cookie;
}
$res = $db->query('Select id from '.$db->prefix.'posts where topic_id='.$id.' ORDER BY id');
$rec = $db->fetch_row($res);
While($rec){
$headers[]=$rec;
$rec = $db->fetch_row($res);
}
$madechange=false;
@reset($headers);
$row=@current($headers);
while(!empty($row[0])){
if(empty($haveread[$row[0]]) && $row[0] > $old_message){
$madechange=true;
if(empty($$haveread_cookie)){
$haveread[$$new_cookie] = true;
$$haveread_cookie=$$new_cookie;
}
$$haveread_cookie.=".";
$$haveread_cookie.=$row[0];
}
$haveread[$row[0]] = true;
$max_id=$row[0];
$row=next($headers);
}
if ($madechange) {
SetCookie($haveread_cookie,$$haveread_cookie,0);
}
if($$new_cookie<$max_id){
$$new_cookie=$max_id;
SetCookie($new_cookie,$$new_cookie,time()+ 31536000);
}
That's all !