// -------------------- Threads list --------------------
$output = '';
if ($editthread)
$TP['threadlistEditformLink'] = UnbLink('@this', 'id=' . $toplevel, true);
// ----- Look for threads on this page or accept $limit parameter -----
$legend_icon_new = false;
$legend_icon_hot = false;
$legend_icon_important = false;
$legend_icon_closed = false;
$legend_icon_own = false;
$legend_icon_moved = false;
$start_num = 0;
if ($limit == '')
{
if ($threads_per_page)
{
$start_num = ($page - 1) * $threads_per_page;
$limit = $start_num . ',' . $threads_per_page;
}
else
$limit = '';
}
$defaultOrder = false;
if ($order == '')
{
$defaultOrder = true;
$order = ($get == '' ? '(Options & ' . UNB_THREAD_IMPORTANT . ') DESC, ' : '') . 'LastPostDate DESC';
}
$threads = $thread->FindArray($where, $order, $limit, $showhidden);
// read all threads' first posts' users into the cache
foreach($threads as $record)
if (!
in_array($record['User'],
$users) &&
$record['User'] >
0 && !
isset($UNB['UserCache'][$record['User']]))
UnbBuildEntireUserCache($users);
foreach($threads as $record) array_push($a,
$record['ID']);
$user_reads = UnbReadUserReads($a);
$last_posts = UnbGetLastPost($a);
if ($mark_own_posts) $users_posts = UnbFindUsersPosts($a);
if ($advanced_counter && $show_view_count) $count_userviews = UnbCountUserViews($a);
if ($advanced_counter) $count_replyusers = UnbCountReplyUsers($a);
$count = 0; // number of displayed threads
$countNormal = 0; // number of displayed threads that are not important
$prevIsOld = false; // true from the first thread on that is older (LastPostDate) than the user's last login
$prevIsImportant = false; // true from the first important thread on
$new_threads = 0;
foreach($threads as $record)
{
$impclass = '';
$thread->LoadFromRecord($record); // load thread as if it came directly from the database record
$tpitem['id'] = $thread->GetID();
$tpitem['defaultOrder'] = $defaultOrder;
$tpitem['num'] = $count;
$tpitem['numAll'] = $start_num + $count;
if (!UnbCheckRights('viewforum', $thread->GetForum(), $thread->GetID())) continue;
// is this a 'moved' thread that expired?
if ($thread->IsMovedExpired())
{
$thread->RemoveAllPosts();
continue;
}
if (!$count)
{
// If the first thread in the list is not important (and thus sorted out of date),
// remember we already have an 'old' thread from the beginning on
if (!$thread->IsImportant())
$prevIsOld = $thread->GetLastPostDate() < $UNB['LoginUser']->GetLastLogout();
// Remember if the first thread displayed is important
$firstIsImportant = $thread->IsImportant();
}
if ($forumid != -1 &&
$prevIsImportant &&
!$thread->IsImportant() &&
$defaultOrder)
{
// This is the first thread that is not important
$prevIsImportant = false;
$tpitem['importantDelimiter'] = true;
}
elseif ($thread->IsImportant())
{
$prevIsImportant = true;
$impclass = 'important';
}
if (($countNormal || $firstIsImportant) && // not the first normal (=not important) thread displayed
// OR first thread displayed was important
// (we need a distance then, too)
!$prevIsOld && // previous isn't already old
(!$thread->IsImportant() || $forumid == -1) && // this is not important OR importants are sorted in
$thread->GetLastPostDate() < $UNB['LoginUser']->GetLastLogout() /*&& // this is an old thread
$defaultOrder*/)
{
// This is the first post that is older (LastPostDate) than the user's last login
$prevIsOld = true;
if (($countNormal || !$firstIsImportant) && // not the first normal thread displayed
// OR first thread was not important
// MEANS: if the first was important, we need a normal in between
$forumid == -1 && // only show this space for search results, not forums
stristr($order,
'LastPostDate')) // LastPostDate must play a role in sorting
{
// Only show the message/space if there was a normal post already OR the first one wasn't important
$tpitem['oldDelimiter'] = true;
}
}
//$lastpost = UnbGetLastPost("Thread=" . $thread->GetID());
$lastpost = $last_posts[$thread->GetID()];
//$lastread = $thread->GetLastRead();
$lastread = $user_reads[$thread->GetID()]['LastRead'];
$target = $thread->GetID();
if ($thread->
IsMoved()) $target =
intval($thread->
GetQuestion());
// ----- ICON -----
$img = 'thread';
$title = $UNB_T['topic'];
$jmp_new = '';
$flag_moved = $thread->IsMoved();
$flag_new = $lastpost['Date'] > $lastread && $UNB['LoginUserID'];
$flag_own =
$mark_own_posts &&
$UNB['LoginUserID'] >
0 &&
in_array($thread->
GetID(),
$users_posts);
$flag_closed = $thread->IsClosed();
$flag_imp = $thread->IsImportant();
$flag_hot = (rc('hot_thread_posts') && UnbGetPostsByThread($thread->GetID()) > rc('hot_thread_posts') ||
rc('hot_thread_views') && $thread->GetViews() > rc('hot_thread_views'));
if ($flag_moved) $flag_new = $flag_own = $flag_closed = $flag_imp = false;
#if ($flag_imp) $flag_own = false;
if ($flag_imp) $flag_hot = false;
if ($flag_moved)
{
$img .= '_moved';
$title = $UNB_T['img.moved thread'];
$legend_icon_moved = true;
}
if ($flag_imp)
{
$title = $UNB_T['img.important thread'];
$legend_icon_important = true;
}
if ($flag_closed)
{
$title = $UNB_T['img.closed thread'];
$legend_icon_closed = true;
}
if ($flag_new)
{
$img .= '_new';
$title .= ' (' . $UNB_T['img.new posts'] . ')';
$new_threads++;
$legend_icon_new = true;
// direct link to 1st unread post, only if user has already read something there before
if ($lastread)
{
$jmp_new = UnbMakePostLink($thread->FirstUnreadPost($lastread), 0, true) . '<img ' . $UNB['Image']['unread'] . ' title="' . $UNB_T['img.goto unread post'] . '" /> ';
}
}
if ($flag_own)
{
$img .= '_own';
$title .= ' (' . $UNB_T['img.own posts'] . ')';
$legend_icon_own = true;
}
if ($flag_closed)
{
$img .= '_closed';
}
if ($flag_imp)
{
$img .= '_important';
}
else if ($flag_hot)
{
$img .= '_hot';
//$title = $UNB_T['hot_thread'];
$legend_icon_hot = true;
}
$tpitem['impclass'] = $impclass;
$tpitem['editThis'] =
($thread->GetID() == $editthread && UnbCheckRights('editpost', $thread->GetForum(), $thread->GetID(), 0));
$tpitem['linkThreadIcon'] = UnbLink('@thread', 'id=' . $target, true);
$tpitem['image'] = $UNB['Image'][$img];
$tpitem['imageTitle'] = $title;