MyBB Community Forums

Full Version: Subscribed Threads On Index
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4
Hi,

I am looking for something to display a users subscribed threads on the index. I will also need to pull the avatar of the last poster. Here is what I would like it to look like... https://dl.dropbox.com/u/54081213/r/dg/index.png . Yaldaram provided me with this code but it sadly doesn't display a thing Sad. Any ideas?

Thank you Smile
I've replied to your PM, Jason.
Bump...still need help...
Your image is not very describing, at least for me.
I think he attached the wrong pic
Sure did...sorry. Here you are: https://dl.dropbox.com/u/54081213/r/dg/index.png

Sorry about that.
So it just shows the latest updates to your subscribed threads like how it currently works in the UCP? You will need a plugin for it, it should be rather simple one.
(2012-11-18, 01:33 AM)Omar G. Wrote: [ -> ]So it just shows the latest updates to your subscribed threads like how it currently works in the UCP? You will need a plugin for it, it should be rather simple one.

Yes sir. That's precisely what it needs to do. I am a dummy when it comes to PHP though.
Regarding your PM, I currently lack of time to take plugin requests, being paid or free ones, unfortunately. As a quick solution, use this.

Open your index.php and find:
eval("\$index = \"".$templates->get("index")."\";");

Add before:
// Thread Subscriptions with New Posts
$latest_subscribed = '';
if($mybb->user['uid'])
{
	$query = $db->simple_select("threadsubscriptions", "sid", "uid = '".$mybb->user['uid']."'", array("limit" => 1));
	if($db->num_rows($query))
	{
		$visible = "AND t.visible != 0";
		if(is_moderator() == true)
		{
			$visible = '';
		}

		$query = $db->query("
			SELECT s.*, t.*, t.username AS threadusername, u.username
			FROM ".TABLE_PREFIX."threadsubscriptions s
			LEFT JOIN ".TABLE_PREFIX."threads t ON (s.tid=t.tid)
			LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
			WHERE s.uid='".$mybb->user['uid']."' {$visible}
			ORDER BY t.lastpost DESC
			LIMIT 0, 10
		");
		
		$fpermissions = forum_permissions();
		while($subscription = $db->fetch_array($query))
		{
			$forumpermissions = $fpermissions[$subscription['fid']];
			if($forumpermissions['canview'] != 0 || $forumpermissions['canviewthreads'] != 0)
			{
				$subscriptions[$subscription['tid']] = $subscription;
			}
		}
		
		if(is_array($subscriptions))
		{
			$tids = implode(",", array_keys($subscriptions));

			// Checking read
			if($mybb->settings['threadreadcut'] > 0)
			{
				$query = $db->simple_select("threadsread", "*", "uid='{$mybb->user['uid']}' AND tid IN ({$tids})");
				while($readthread = $db->fetch_array($query))
				{
					if($readthread['dateline'] >= $subscriptions[$readthread['tid']]['lastpost'])
					{
						unset($subscriptions[$readthread['tid']]); // If it's already been read, then don't display the thread
					}
					else
					{			
						$subscriptions[$readthread['tid']]['lastread'] = $readthread['dateline'];
					}
				}
			}
			
			if($subscriptions)
			{
				if($mybb->settings['dotfolders'] != 0)
				{
					$query = $db->simple_select("posts", "tid,uid", "uid='{$mybb->user['uid']}' AND tid IN ({$tids})");
					while($post = $db->fetch_array($query))
					{
						$subscriptions[$post['tid']]['doticon'] = 1;
					}
				}

				$icon_cache = $cache->read("posticons");
				$lang->load('usercp');
				$threadprefixes = $cache->read('threadprefixes');
				foreach($subscriptions as $thread)
				{
					$folder = '';
					$folder_label = '';
					$gotounread = '';

					if($thread['tid'])
					{
						$bgcolor = alt_trow();
						$thread['subject'] = $parser->parse_badwords($thread['subject']);
						$thread['subject'] = htmlspecialchars_uni($thread['subject']);
						$thread['threadlink'] = get_thread_link($thread['tid']);
						$thread['lastpostlink'] = get_thread_link($thread['tid'], 0, "lastpost");

						// If this thread has a prefix...
						if($thread['prefix'] && isset($threadprefixes[$thread['prefix']]))
						{
							$thread['displayprefix'] = $threadprefixes[$thread['prefix']]['displaystyle'].' ';
						}
						else
						{
							$thread['displayprefix'] = '';
						}

						// Icons
						if($thread['icon'] > 0 && $icon_cache[$thread['icon']])
						{
							$icon = $icon_cache[$thread['icon']];
							$icon = "<img src=\"{$icon['path']}\" alt=\"{$icon['name']}\" />";
						}
						else
						{
							$icon = "&nbsp;";
						}
						
						if($thread['doticon'])
						{
							$folder = "dot_";
							$folder_label .= $lang->icon_dot;
						}
						
						// Check to see which icon we display
						if($thread['lastread'] && $thread['lastread'] < $thread['lastpost'])
						{
							$folder .= "new";
							$folder_label .= $lang->icon_new;
							$new_class = "subject_new";
							$thread['newpostlink'] = get_thread_link($thread['tid'], 0, "newpost");
							eval("\$gotounread = \"".$templates->get("forumdisplay_thread_gotounread")."\";");
						}
						else
						{
							$folder_label .= $lang->icon_no_new;
							$new_class = "subject_old";
						}
						
						$folder .= "folder";

						if($thread['visible'] == 0)
						{
							$bgcolor = "trow_shaded";
						}
		
						$lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']);
						$lastposttime = my_date($mybb->settings['timeformat'], $thread['lastpost']);
						$lastposter = $thread['lastposter'];
						$lastposteruid = $thread['lastposteruid'];
		
						if($lastposteruid == 0)
						{
							$lastposterlink = $lastposter;
						}
						else
						{
							$lastposterlink = build_profile_link($lastposter, $lastposteruid);
						}
			
						$thread['replies'] = my_number_format($thread['replies']);
						$thread['views'] = my_number_format($thread['views']);
						$thread['author'] = build_profile_link($thread['username'], $thread['uid']);

						eval("\$latest_subscribed_threads .= \"".$templates->get("usercp_latest_subscribed_threads")."\";");
					}
				}
				eval("\$latest_subscribed = \"".$templates->get("usercp_latest_subscribed")."\";");
			}
		}
	}
}

(UserCP code with some changes.)

If you want to save one query, remove (from the above code):
$templates->cache('forumdisplay_thread_gotounread,usercp_latest_subscribed_threads,usercp_latest_subscribed');

However I'm not entitled sure about the real performance increase or decrease.

Find (at the beginning of the index.php file):
$templatelist .= ",index_birthdays_birthday,index_birthdays,index_pms,index_loginform,index_logoutlink,index_stats,forumbit_depth3,forumbit_depth3_statusicon,index_boardstats";

And add after:
$templatelist .= 'forumdisplay_thread_gotounread,usercp_latest_subscribed_threads,usercp_latest_subscribed';

Now open your index template and add the following variable wherever you want the box to be shown.
{$latest_subscribed}

This will a add a new query for your registered users and at least 3 if they have thread subscriptions with new posts.

This will use the UserCP templates (forumdisplay_thread_gotounread, usercp_latest_subscribed_threads, and usercp_latest_subscribed). If you want to use different templates then create new ones with the original's content and do the necessary modifications to the code I provided. You can also use the Template Conditionals plugin for avoiding all that pain.
<if THIS_SCRIPT == 'index.php' then>
index box design
<else>
default code
</if>

Good luck.
Hi Omar,

Unfortunately, it did not work Sad. Nothing is displayed at all. Should I just give up on the possibility of this working?
Pages: 1 2 3 4