Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

Counting unread forum threads/posts

Asked Modified Viewed 3,843 times
C
Creatium
C
  • Member, joined since
  • Contributed 93 posts on the community forums.
  • Started 9 threads in the forums
  • Started this discussions
asked
Member

Hey,
is there a way on fusion to count all unread forum threads for every user? It would be something like "number of threads I have not read yet: 35". Is it something that can be done?
0 replies

2 posts

F
Falk
F
Falk 131
Need help?, Having trouble?
• View our Documentation for Guides, Standards and Functions
• Name and Organize your Topics and Content correctly in the corresponding Forums for best support results
• Attaching Log Files and Screenshots when reporting issues will help
• Provide with an URL to live example if one exists
• Please read the How to Report an Error post
• Please read and comply with the Code of Conduct

(¯·._.·(¯°·._.·°º*[ Project Manager ]*º°·._.·°¯)·._.·¯)
  • Super Admin, joined since
  • Contributed 6,201 posts on the community forums.
  • Started 639 threads in the forums
  • Answered 11 questions
answered
Super Admin

Heya,

Here is a start for ya

<?php
/*-------------------------------------------------------+
| PHPFusion Content Management System
| Copyright (C) 2002 - 2011 Nick Jones
| http://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: unanswered_threads.php
| Author: Nick Jones (Digitanium)
| Adapted by Philip
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/

require_once "maincore.php";
require_once THEME."theme.php";

global $lastvisited;

if (!isset($lastvisited) || !isnum($lastvisited)) { $lastvisited = time(); }

if (isset($_GET['rowstart']) && isnum($_GET['rowstart'])) {
      $rowstart = $_GET['rowstart'];
   } else {
      $rowstart = 0;
   }
   
 $thread_count = (dbcount("(thread_id)", DB_THREADS, "thread_postcount = 1"));
 $week_time = (time() + ($settings['timeoffset'] * 3600));
 $week_utotal = (dbcount("(thread_id)", DB_THREADS, "thread_lastpost + 604800 > $week_time AND thread_postcount = 1"));
 $week_total = (dbcount("(thread_id)", DB_THREADS, "thread_lastpost + 604800 > $week_time"));

 $all_utotal = (dbcount("(thread_id)", DB_THREADS, "thread_postcount = 1"));
 $all_total = (dbcount("(thread_id)", DB_THREADS));

$result = dbquery(
   "SELECT tt.thread_id, tt.thread_subject, tt.thread_views, tt.thread_lastuser, tt.thread_lastpost,
   tt.thread_poll, tf.forum_id, tf.forum_name, tf.forum_access, tt.thread_lastpostid, tt.thread_postcount, tu.user_id, tu.user_name
   FROM ".DB_THREADS." tt
   INNER JOIN ".DB_FORUMS." tf ON tt.forum_id=tf.forum_id
   INNER JOIN ".DB_USERS." tu ON tt.thread_lastuser=tu.user_id
   WHERE tf.forum_id !='50' AND tf.forum_id !='77' AND tf.forum_id !='78' AND tf.forum_id !='79' AND tf.forum_id !='80' AND tf.forum_id !='83'
   AND ".groupaccess('tf.forum_access')." AND tt.thread_postcount = 1
   ORDER BY tt.thread_lastpost DESC LIMIT $rowstart,50
");


if (dbrows($result)) {

   $i = 0;
   echo "<table cellpadding='0' cellspacing='1' width='100%' class='tbl-border'>\n<tr>\n";
      echo "<td class='tbl2'>&nbsp;</td>\n";
   echo "<td class='tbl2'><strong>Total Threads: ".$all_total."<br />
                                  Total Unanswered: ".$thread_count."<br />
                                  Overall percentage: ".round($all_utotal*100/$all_total)."%
                                  </strong></td>\n";
                                  
   echo "<td class='tbl2' align='left' colspan='3'><strong>Total this week: ".$week_total."<br />
                                                             Unanswered: ".$week_utotal."<br />
                                                             Weeks percentage: ".round($week_utotal*100/$week_total)."%
                                                             </strong></td>\n";
   echo "</tr>\n<tr>\n";
   echo "<td class='tbl2'>&nbsp;</td>\n";
   echo "<td width='100%' class='tbl2'><strong>".$locale['global_044']."</strong></td>\n";
   echo "<td width='1%' class='tbl2' style='text-align:center;white-space:nowrap'><strong>".$locale['global_045']."</strong></td>\n";
   echo "<td width='1%' class='tbl2' style='text-align:center;white-space:nowrap'><strong>".$locale['global_046']."</strong></td>\n";
   echo "<td width='1%' class='tbl2' style='text-align:center;white-space:nowrap'><strong>".$locale['global_047']."</strong></td>\n";
   echo "</tr>\n";
   while ($data = dbarray($result)) {

      $row_color = ($i % 2 == 0 ? "tbl1" : "tbl2");
      echo "<tr>\n<td class='".$row_color."'>";
      if ($data['thread_lastpost'] > $lastvisited) {
         $thread_match = $data['thread_id']."\|".$data['thread_lastpost']."\|".$data['forum_id'];
         if (iMEMBER && preg_match("(^\.{$thread_match}$|\.{$thread_match}\.|\.{$thread_match}$)", $userdata['user_threads'])) {

            echo "<img src='".get_image("folder")."' alt='' />";
         } else {
            echo "<img src='".get_image("foldernew")."' alt='' />";
         }

      } else {
         echo "<img src='".get_image("folder")."' alt='' />";
      }

      if ($data['thread_poll']) {

         $thread_poll = "<span class='small' style='font-weight:bold'>[".$locale['global_051']."]</span> ";
      } else {

         $thread_poll = "";
      }

      echo "</td>\n";
      echo "<td width='100%' class='".$row_color."'>".$thread_poll."<a href='".FORUM."viewthread.php?thread_id=".$data['thread_id']."&amp;pid=".$data['thread_lastpostid']."#post_".$data['thread_lastpostid']."' title='".$data['thread_subject']."'>".trimlink($data['thread_subject'], 30)."</a><br />\n".$data['forum_name']."</td>\n";
      echo "<td width='1%' class='".$row_color."' style='text-align:center;white-space:nowrap'>".$data['thread_views']."</td>\n";
      echo "<td width='1%' class='".$row_color."' style='text-align:center;white-space:nowrap'>".($data['thread_postcount']-1)."</td>\n";
      echo "<td width='1%' class='".$row_color."' style='text-align:center;white-space:nowrap'><a href='".BASEDIR."profile.php?lookup=".$data['thread_lastuser']."'>".$data['user_name']."</a><br />\n".showdate("forumdate", $data['thread_lastpost'])."</td>\n";
      echo "</tr>\n";
      $i++;
   }

   echo "</table>\n";
}

if ($thread_count > 50) echo "<div align='center' style=';margin-top:5px;'>\n".makepagenav($rowstart,50,$thread_count,3,FUSION_SELF."?page_id=".$_GET['page_id']."&amp;")."\n</div>\n";

?>
0 replies
C
Creatium
C
  • Member, joined since
  • Contributed 93 posts on the community forums.
  • Started 9 threads in the forums
  • Started this discussions
answered
Member

This isn't really what I need.

What I need is if there are 5 new posts since my last visit/view of thread - code will show 5. It would be something like counting "new post" icons in the forum_threads_list_panel, but in my case it would count all the "new post" icons of threads I have not read (since my last visit).

---------------------

Merged on Feb 21 2014 at 19:13:47:

I made it. Seems to work fine. Just for those, who are checking whole forum, I suggest adding LIMIT to the query.


$result = dbquery("SELECT tt.forum_id,thread_id,thread_replies,thread_lastuser,thread_lastpost,
      tu.user_id,user_name
      FROM ".DB_THREADS." tt
      INNER JOIN ".DB_USERS." tu ON tt.thread_lastuser=tu.user_id
      WHERE tt.thread_deleted='0' ORDER BY thread_lastpost DESC"
);

   $new_unread_posts = 0;
   while ($data = dbarray($result)) {
      $found = strstr($userdata['user_last_threads'], $data['thread_id']."|") ? 1 : 0;
      if($found) {
         $first_act = substr(strstr($userdata['user_last_threads'], $data['thread_id']."|"),strlen($data['thread_id'])+1,22);
         $secont_act = explode(",",$first_act);
         $last_tvisit = substr($secont_act['0'],-10);
         $new_posts = $last_tvisit <= $data['thread_lastpost'] ? 1 : 0;
         if($new_posts) { $new_unread_posts++; }
      }
   }
   
      echo "Unread posts ".$new_unread_posts."";
Edited by Creatium on 21-02-2014 19:14,
0 replies

Labels

None yet

Statistics

  • Views 0 views
  • Posts 2 posts
  • Votes 0 votes
  • Topic users 2 members

2 participants

F
F
Falk 131
Need help?, Having trouble?
• View our Documentation for Guides, Standards and Functions
• Name and Organize your Topics and Content correctly in the corresponding Forums for best support results
• Attaching Log Files and Screenshots when reporting issues will help
• Provide with an URL to live example if one exists
• Please read the How to Report an Error post
• Please read and comply with the Code of Conduct

(¯·._.·(¯°·._.·°º*[ Project Manager ]*º°·._.·°¯)·._.·¯)
  • Super Admin, joined since
  • Contributed 6,201 posts on the community forums.
  • Started 639 threads in the forums
  • Answered 11 questions
C
C
  • Member, joined since
  • Contributed 93 posts on the community forums.
  • Started 9 threads in the forums
  • Started this discussions

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet