Ignore:
Timestamp:
02/27/08 22:01:07 (4 years ago)
Author:
hverton
Message:

updated the forum_threads_list_panel module to make use of the thread_first_read functionality

File:
1 edited

Legend:

Unmodified
Added
Removed
  • modules/common/forum_threads_list_panel/php-files/modules/forum_threads_list_panel/new_posts.php

    r1282 r1318  
    3737            WHERE tr.user_id = '".$userdata['user_id']."' 
    3838                AND (p.post_datestamp > ".$settings['unread_threshold']." OR p.post_edittime > ".$settings['unread_threshold'].") 
    39                 AND (p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read) 
     39                AND ((p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read) 
     40                    OR (p.post_datestamp < tr.thread_first_read OR (p.post_edittime != 0 AND p.post_edittime < tr.thread_first_read))) 
    4041            GROUP BY p.thread_id 
    4142        "); 
    4243    // update the last_read datestamp of all threads found 
    4344    while ($data = dbarray($result)) { 
    44         $result2 = dbquery("UPDATE ".$db_prefix."threads_read SET thread_last_read = '".time()."' WHERE user_id = '".$userdata['user_id']."' AND thread_id = '".$data['thread_id']."'"); 
     45        $result2 = dbquery("UPDATE ".$db_prefix."threads_read SET thread_first_read = '0', thread_last_read = '".time()."' WHERE user_id = '".$userdata['user_id']."' AND thread_id = '".$data['thread_id']."'"); 
    4546    } 
    4647    // done, fall back to the homepage 
     
    5354// check if there are any unread posts for this user 
    5455if ($userdata['user_posts_unread']) { 
    55     $result = dbquery("SELECT count(*) as unread, sum(tr.thread_page) AS pages FROM ".$db_prefix."posts p LEFT JOIN ".$db_prefix."threads_read tr ON p.thread_id = tr.thread_id WHERE tr.user_id = '".$userdata['user_id']."' AND (p.post_datestamp > ".$settings['unread_threshold']." OR p.post_edittime > ".$settings['unread_threshold'].") AND (p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read)", false); 
     56    $result = dbquery(" 
     57        SELECT count(*) as unread  
     58            FROM ".$db_prefix."posts p  
     59                LEFT JOIN ".$db_prefix."threads_read tr ON p.thread_id = tr.thread_id  
     60            WHERE tr.user_id = '".$userdata['user_id']."'  
     61                AND (p.post_datestamp > ".$settings['unread_threshold']." OR p.post_edittime > ".$settings['unread_threshold'].") 
     62                AND ((p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read) 
     63                    OR (p.post_datestamp < tr.thread_first_read OR (p.post_edittime != 0 AND p.post_edittime < tr.thread_first_read)))" 
     64        ); 
    5665} else { 
    57     $result = dbquery("SELECT count(*) as unread, sum(tr.thread_page) AS pages FROM ".$db_prefix."posts p LEFT JOIN ".$db_prefix."threads_read tr ON p.thread_id = tr.thread_id WHERE tr.user_id = '".$userdata['user_id']."' AND p.post_author != '".$userdata['user_id']."' AND p.post_edituser != '".$userdata['user_id']."' AND (p.post_datestamp > ".$settings['unread_threshold']." OR p.post_edittime > ".$settings['unread_threshold'].") AND (p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read)", false); 
    58 } 
     66    $result = dbquery(" 
     67        SELECT count(*) as unread  
     68            FROM ".$db_prefix."posts p  
     69                LEFT JOIN ".$db_prefix."threads_read tr ON p.thread_id = tr.thread_id  
     70            WHERE tr.user_id = '".$userdata['user_id']."'  
     71                AND p.post_author != '".$userdata['user_id']."' 
     72                AND p.post_edituser != '".$userdata['user_id']."' 
     73                AND (p.post_datestamp > ".$settings['unread_threshold']." OR p.post_edittime > ".$settings['unread_threshold'].") 
     74                AND ((p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read) 
     75                    OR (p.post_datestamp < tr.thread_first_read OR (p.post_edittime != 0 AND p.post_edittime < tr.thread_first_read)))" 
     76        ); 
     77}  
    5978$variables['unread'] = ($result ? mysql_result($result, 0) : 0); 
     79 
     80// make sure rowstart has a valid value 
     81if (!isset($rowstart) || !isNum($rowstart)) $rowstart = 0; 
     82$variables['rowstart'] = $rowstart; 
    6083 
    6184// and if so, get them 
     
    6790        $result = dbquery(" 
    6891            SELECT p.forum_id, p.thread_id, count( * ) AS unread, f.forum_name, f.forum_cat, t.thread_subject, t.thread_views, t.thread_lastpost, MIN( p.post_id ) AS post_id 
    69                 FROM ".$db_prefix."posts p 
     92                FROM ".$db_prefix."posts p  
    7093                LEFT JOIN ".$db_prefix."forums f ON p.forum_id = f.forum_id 
    7194                LEFT JOIN ".$db_prefix."threads t ON p.thread_id = t.thread_id 
    7295                LEFT JOIN ".$db_prefix."threads_read tr ON p.thread_id = tr.thread_id 
    73                 WHERE tr.user_id = '".$userdata['user_id']."' 
     96                WHERE tr.user_id = '".$userdata['user_id']."'  
    7497                    AND (p.post_datestamp > ".$settings['unread_threshold']." OR p.post_edittime > ".$settings['unread_threshold'].") 
    75                     AND (p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read) 
     98                    AND ((p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read) 
     99                        OR (p.post_datestamp < tr.thread_first_read OR (p.post_edittime != 0 AND p.post_edittime < tr.thread_first_read))) 
    76100                GROUP BY p.thread_id 
    77             "); 
     101                ORDER BY t.thread_lastpost ASC 
     102                LIMIT ".$rowstart.", ".ITEMS_PER_PAGE 
     103            ); 
    78104    } else { 
    79105        $result = dbquery(" 
    80106            SELECT p.forum_id, p.thread_id, count( * ) AS unread, f.forum_name, f.forum_cat, t.thread_subject, t.thread_views, t.thread_lastpost, MIN( p.post_id ) AS post_id 
    81                 FROM ".$db_prefix."posts p 
     107                FROM ".$db_prefix."posts p  
    82108                LEFT JOIN ".$db_prefix."forums f ON p.forum_id = f.forum_id 
    83109                LEFT JOIN ".$db_prefix."threads t ON p.thread_id = t.thread_id 
    84110                LEFT JOIN ".$db_prefix."threads_read tr ON p.thread_id = tr.thread_id 
    85                 WHERE tr.user_id = '".$userdata['user_id']."' 
     111                WHERE tr.user_id = '".$userdata['user_id']."'  
    86112                    AND p.post_author != '".$userdata['user_id']."' 
    87113                    AND p.post_edituser != '".$userdata['user_id']."' 
    88114                    AND (p.post_datestamp > ".$settings['unread_threshold']." OR p.post_edittime > ".$settings['unread_threshold'].") 
    89                     AND (p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read) 
     115                    AND ((p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read) 
     116                        OR (p.post_datestamp < tr.thread_first_read OR (p.post_edittime != 0 AND p.post_edittime < tr.thread_first_read))) 
    90117                GROUP BY p.thread_id 
    91             "); 
    92     } 
     118                ORDER BY t.thread_lastpost ASC 
     119                LIMIT ".$rowstart.", ".ITEMS_PER_PAGE 
     120            ); 
     121    }  
    93122    // get the number of unread threads 
    94123    $rows = dbrows($result); 
    95124    $variables['rows'] = $rows; 
    96  
    97     // make sure rowstart has a valid value 
    98     if (!isset($rowstart) || !isNum($rowstart)) $rowstart = 0; 
    99     $variables['rowstart'] = $rowstart; 
    100125 
    101126    // add additional info to the data retrieved 
Note: See TracChangeset for help on using the changeset viewer.