MyBB Hacks

Full Version: Forum Name In Portal Announcement
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Useless maybe. But I just want to share this. I hope it is OK Biggrin

This is a very simple plugin for displaying forum name and forum link for each announcements in portal announcements.

Put {$mnann_forum_name} variable in portal_announcement template.

[attachment=440]
Yea, I like this - I have something similar, but not coolly IN the announcement text.
We can place the variable anywhere in that template. It is for example only Biggrin

If we are a fans of PHP In Template or Template Conditional plugins (and I'm a fans of PHP In Template plugin Biggrin), we don't need it. We can use those plugins for this. And if we use XThreads, it is more easier for us, because we can use (I think) {$forumurl} variable as forum link.
Yea, this is the code I use in my prefix_portal_announcement

HTML Code
<table cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder">
	<tr>
		<td class="thead" colspan="{$colspan}">
			<div style="float: right;">
				<span><strong><a href="{$mybb->settings['bburl']}/forum-{$announcement['fid']}.html">{$announcement['forumname']}</a></strong></span>
			</div>
			<div style="float: left;">{$icon}</div><div><strong><a href="{$mybb->settings['bburl']}/showthread.php?tid={$announcement['tid']}">{$announcement['subject']}</a></strong>				
		</div>
		</td>
	</tr>

<tr>
<td class="trow1" align="right">
<span class="smalltext">{$lang->posted_by} <a href="{$mybb->settings['bburl']}/member.php?action=profile&amp;uid={$announcement['uid']}">{$announcement['username']}</a>  - {$anndate} {$anntime} {$numcomments}</span>
</td>
</tr>
<tr>
<td class="fancy" colspan="5"><span class="smalltext"></span></td>
</tr>
<tr>
<td class="trow1">
<table border="0" cellpadding="{$theme['tablespace']}" width="100%">
<tr>
<td>
<div class="trow1"><img src="{$GLOBALS['threadfields']['book_jacket']['url']}/thumb320x240" alt="gahhhh" /></div>
</td>
<td>
<div class="trow1">{$message}</div><br />
<div class="trow1" ><a href="{$mybb->settings['bburl']}/showthread.php?tid={$announcement['tid']}"><span class="smalltext"><em>Read More</em></span></a></div><br />
</td>
</tr>
</table>
</td>
</tr>
</table>
<br />


Its just a template edit. Maybe its inefficient like this?

Nice idea RateU Smile
@ Leefish: I don't know what do you mean by "inefficient", Lee. Do you use a plugin for this? Because I can't find the {$announcement['forumname']} as a default variable in portal announcement.....
Oh yes. I forgot - I also edited my portal.php for the latest threads box. I added a couple of variables into the announcements bit....That way you can jump through to the forum from the latest threads box. Re inefficient - I mean changing templates and whatnot rather than a neat plugin. Especially if its using Zinga Burga's control object.

Here is the code from my portal.php, but I don't think this was the cause...... (made it a while ago)

PHP Code:
// Latest forum discussions
if($mybb->settings['portal_showdiscussions'] != 0 && $mybb->settings['portal_showdiscussionsnum'])
{
	$altbg = alt_trow();
	$threadlist = '';
	$uv = str_replace('fid', 't.fid', $unviewwhere);
	$query = $db->query("
		SELECT t.*, u.username, f.name AS forumname
		FROM ".TABLE_PREFIX."threads t
		LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
		LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=t.fid)
		WHERE 1=1 $uv AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
		AND t.fid NOT IN(15,20,43,44,68,45)
		ORDER BY t.lastpost DESC 
		LIMIT 0, ".$mybb->settings['portal_showdiscussionsnum']
	);
	while($thread = $db->fetch_array($query))
	{
		$lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']);
		$lastposttime = my_date($mybb->settings['timeformat'], $thread['lastpost']);
		// Don't link to guest's profiles (they have no profile).
		if($thread['lastposteruid'] == 0)
		{
			$lastposterlink = $thread['lastposter'];
		}
		else
		{
			$lastposterlink = build_profile_link($thread['lastposter'], $thread['lastposteruid']);
		}
		if(my_strlen($thread['subject']) > 25)
		{
			$thread['subject'] = my_substr($thread['subject'], 0, 25) . "...";
		}
$thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject']));
$thread['threadlink'] = get_thread_link($thread['tid']);
$thread['lastpostlink'] = get_thread_link($thread['tid'], 0, "lastpost");
eval("\$threadlist .= \"".$templates->get("portal_latestthreads_thread")."\";");
$altbg = alt_trow();
	}
	if($threadlist)
	{ 
		// Show the table only if there are threads
		eval("\$latestthreads = \"".$templates->get("portal_latestthreads")."\";");
	}
}

// Get latest news announcements
// First validate announcement fids:
$announcementsfids = explode(',', $mybb->settings['portal_announcementsfid']);
if(is_array($announcementsfids))
{
	foreach($announcementsfids as $fid)
	{
		$fid_array[] = intval($fid);
	}
	$announcementsfids = implode(',', $fid_array);
}
// And get them!
$query = $db->simple_select("forums", "*", "fid IN (".$announcementsfids.")");
while($forumrow = $db->fetch_array($query))
{
    $forum[$forumrow['fid']] = $forumrow;
}

$pids = '';
$tids = '';
$comma = '';
$query = $db->query("
	SELECT p.pid, p.message, p.tid, p.smilieoff
	FROM ".TABLE_PREFIX."posts p
	LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
	WHERE t.fid IN (".$announcementsfids.") AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.firstpost=p.pid
	ORDER BY t.dateline DESC 
	LIMIT 0, ".$mybb->settings['portal_numannouncements']
);
while($getid = $db->fetch_array($query))
{
	$pids .= ",'{$getid['pid']}'";
	$tids .= ",'{$getid['tid']}'";
	$posts[$getid['tid']] = $getid;
}
$pids = "pid IN(0{$pids})";
// Now lets fetch all of the attachments for these posts
$query = $db->simple_select("attachments", "*", $pids);
while($attachment = $db->fetch_array($query))
{
	$attachcache[$attachment['pid']][$attachment['aid']] = $attachment;
}

if(is_array($forum))
{
	foreach($forum as $fid => $forumrow)
	{
		$forumpermissions[$fid] = forum_permissions($fid);
	}
}

$icon_cache = $cache->read("posticons");

Assuming you did the same modification in your announcement query (joining the forum table to get the forum name), and add $announcement['forumname'] to the portal.php, as I said in the previous post, I think we can do that with Template Conditional or PHP In Template only (to get the "proper" forum link and do some "HTML validating" for forum name, if we care about validating our page). If all forums use usual forum name (without HTML entities), it only used for getting the proper forum link. And, if we use XThreads, we can use {$forumurl} variable as forum URL (provided by XThreads in portal announcement).
So, in Portal Announcement, I think we don't need to edit our portal.php file if we only want the forum name and forum link/URL.

Sorry if my opinion above is wrong Biggrin
Yea, so thats what I meant about it being "less efficient" - I was posting all that code to show you that your way was better Smile
For latest thread/discussion block in portal, I think it is a bit similar if we want only to get the forum name and forum URL. We need Template Conditional or PHP In Template plugin for that to get the proper forum link and forum name. I think (again), we can use forum cache for getting the forum name.

But which is better, using code edit or using Template Conditional, the best person can answer this question is Yumi Biggrin
Pages: 1 2
Reference URL's