MyBB Community Forums

Full Version: username markup on author column
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey everyone,

I recently installed a plugin allowing me to have the traditional author column displayed in the forumtopics page. However, when it displays the name of a user that has a custom username markup as defined in the Admin Panel, it doesn't apply to this column, it shows it like everyone else's. My question is: How can I make it to where the authors name has the username markups included if the group has one?

This is the code, I've altered it a couple of times and still got no result, so I am posting the original.

<?php
/**
 * MyBB 1.4 Classic Author Column Plugin
 * by ELY M.
 *
 */

// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

//Thanks to Demonic for this function
//http://community.mybboard.net/thread-39634.html
function classicauthorcolumn_temp_uninstall($title,$find,$replace) {
  global $db;
  $title = $db->escape_string( $title );
  $query = $db->simple_select("templates", "*", "title='$title' AND sid='-2'");
  if( $db->num_rows( $query ) > 0 ) {
    $rows = $db->fetch_array( $query );
    $temp = str_replace($find,$replace, $rows['template']);
    $updatetemp = array("template" => $db->escape_string($temp), "dateline" => TIME_NOW);
    $db->update_query("templates", $updatetemp, "title='$title'");
  }
}
    
function classicauthorcolumn_info()
{
	
	return array(
		"name" => "Classic Author Column",
		"description" => "Classic Author Column in forumdisplay threads",
		"website" => "",
		"author" => "ELY M.",
		"authorsite" => "",
		"version" => "1.0.4",
		"guid" => "ce93d53806d0037002a070fd9fdd8a9b",
		"compatibility" => "14*"
	);
}

function classicauthorcolumn_activate()
{
	require_once MYBB_ROOT."/inc/adminfunctions_templates.php";



  find_replace_templatesets("forumdisplay_threadlist", "#".preg_quote("{\$colspan}")."#i", "9");
  find_replace_templatesets("forumdisplay_threadlist", "#".preg_quote("{\$colspan}")."#i", "9");
  find_replace_templatesets("forumdisplay_thread", "#".preg_quote("<div class=\"author smalltext\">{\$thread['profilelink']}</div>")."#i", "<!-- authornamewashere -->");
  find_replace_templatesets("forumdisplay_threadlist", "#".preg_quote("<td class=\"tcat\" colspan=\"3\" width=\"66%\"><span class=\"smalltext\"><strong><a href=\"{\$sorturl}&amp;sortby=subject&amp;order=asc\">{\$lang->thread}</a> {\$orderarrow['subject']} / <a href=\"{\$sorturl}&amp;sortby=starter&amp;order=asc\">{\$lang->author}</a> {\$orderarrow['starter']}</strong></span></td>")."#i", "<td class=\"tcat\" align=\"center\" colspan=\"3\" width=\"66%\"><span class=\"smalltext\"><strong><a href=\"{\$sorturl}&amp;sortby=subject&amp;order=asc\">{\$lang->thread}</a> {\$orderarrow['subject']}</strong></span></td>");
  find_replace_templatesets("forumdisplay_thread", "#".preg_quote("<td align=\"center\" class=\"{\$bgcolor}\"><a href=\"javascript:MyBB.whoPosted({\$thread['tid']});\">")."#i", "<td align=\"center\" class=\"{\$bgcolor}\">{\$thread['profilelink']}</td>   <td align=\"center\" class=\"{\$bgcolor}\"><a href=\"javascript:MyBB.whoPosted({\$thread['tid']});\">");
  find_replace_templatesets("forumdisplay_threadlist", "#".preg_quote("<td class=\"tcat\" align=\"center\" width=\"7%\"><span class=\"smalltext\"><strong><a href=\"{\$sorturl}&amp;sortby=replies&amp;order=desc\">{\$lang->replies}</a>")."#i", "<td class=\"tcat\" align=\"center\" width=\"10%\"><span class=\"smalltext\"><strong><a href=\"{\$sorturl}&amp;sortby=starter&amp;order=asc\">{\$lang->author}</a> {\$orderarrow['starter']}</strong></span></td>   <td class=\"tcat\" align=\"center\" width=\"7%\"><span class=\"smalltext\"><strong><a href=\"{\$sorturl}&amp;sortby=replies&amp;order=desc\">{\$lang->replies}</a>");
}

function classicauthorcolumn_deactivate()
{
	require_once MYBB_ROOT."/inc/adminfunctions_templates.php";

  classicauthorcolumn_temp_uninstall("forumdisplay_threadlist", "#".preg_quote("9")."#i", "{\$colspan}");
  classicauthorcolumn_temp_uninstall("forumdisplay_threadlist", "#".preg_quote("9")."#i", "{\$colspan}");
  classicauthorcolumn_temp_uninstall("forumdisplay_thread", "#".preg_quote("<!-- authornamewashere -->")."#i", "<div class=\"author smalltext\">{\$thread['profilelink']}</div>");
  classicauthorcolumn_temp_uninstall("forumdisplay_threadlist", "#".preg_quote("<td class=\"tcat\" align=\"center\" colspan=\"3\" width=\"66%\"><span class=\"smalltext\"><strong><a href=\"{\$sorturl}&amp;sortby=subject&amp;order=asc\">{\$lang->thread}</a> {\$orderarrow['subject']}  {\$orderarrow['starter']}</strong></span></td>")."#i", "<td class=\"tcat\" colspan=\"3\" width=\"66%\"><span class=\"smalltext\"><strong><a href=\"{\$sorturl}&amp;sortby=subject&amp;order=asc\">{\$lang->thread}</a> {\$orderarrow['subject']} / <a href=\"{\$sorturl}&amp;sortby=starter&amp;order=asc\">{\$lang->author}</a> {\$orderarrow['starter']}</strong></span></td>");
  classicauthorcolumn_temp_uninstall("forumdisplay_thread", "#".preg_quote("<td align=\"center\" class=\"{\$bgcolor}\">{\$thread['profilelink']}</td>   <td align=\"center\" class=\"{\$bgcolor}\"><a href=\"javascript:MyBB.whoPosted({\$thread['tid']});\">")."#i", "<td align=\"center\" class=\"{\$bgcolor}\"><a href=\"javascript:MyBB.whoPosted({\$thread['tid']});\">");
  classicauthorcolumn_temp_uninstall("forumdisplay_threadlist", "#".preg_quote("<td class=\"tcat\" align=\"center\" width=\"10%\"><span class=\"smalltext\"><strong><a href=\"{\$sorturl}&amp;sortby=starter&amp;order=asc\">{\$lang->author}</a> {\$orderarrow['starter']}</strong></span></td>   <td class=\"tcat\" align=\"center\" width=\"7%\"><span class=\"smalltext\"><strong><a href=\"{\$sorturl}&amp;sortby=replies&amp;order=desc\">{\$lang->replies}</a>")."#i", "<td class=\"tcat\" align=\"center\" width=\"7%\"><span class=\"smalltext\"><strong><a href=\"{\$sorturl}&amp;sortby=replies&amp;order=desc\">{\$lang->replies}</a>");

}



?>



Thanks!
I did a small change to the plugin here:

<?php
/**
* MyBB 1.4 Classic Author Column Plugin
* by ELY M.
*
* Modification by Sayak Banerjee :: sayakb [at] ubuntu [dot] com
* Please note that modifications from sayakb are *untested*.
*
*/

// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
    die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook('forumdisplay_thread', 'classicauthorcolumn_run');

//Thanks to Demonic for this function
//http://community.mybboard.net/thread-39634.html
function classicauthorcolumn_temp_uninstall($title,$find,$replace) {
  global $db;
  $title = $db->escape_string( $title );
  $query = $db->simple_select("templates", "*", "title='$title' AND sid='-2'");
  if( $db->num_rows( $query ) > 0 ) {
    $rows = $db->fetch_array( $query );
    $temp = str_replace($find,$replace, $rows['template']);
    $updatetemp = array("template" => $db->escape_string($temp), "dateline" => TIME_NOW);
    $db->update_query("templates", $updatetemp, "title='$title'");
  }
}
    
function classicauthorcolumn_info()
{
    
    return array(
        "name" => "Classic Author Column",
        "description" => "Classic Author Column in forumdisplay threads",
        "website" => "",
        "author" => "ELY M.",
        "authorsite" => "",
        "version" => "1.0.4",
        "guid" => "ce93d53806d0037002a070fd9fdd8a9b",
        "compatibility" => "14*"
    );
}

function classicauthorcolumn_activate()
{
    require_once MYBB_ROOT."/inc/adminfunctions_templates.php";



  find_replace_templatesets("forumdisplay_threadlist", "#".preg_quote("{\$colspan}")."#i", "9");
  find_replace_templatesets("forumdisplay_threadlist", "#".preg_quote("{\$colspan}")."#i", "9");
  find_replace_templatesets("forumdisplay_thread", "#".preg_quote("<div class=\"author smalltext\">{\$classicauthorcolumn}</div>")."#i", "<!-- authornamewashere -->");
  find_replace_templatesets("forumdisplay_threadlist", "#".preg_quote("<td class=\"tcat\" colspan=\"3\" width=\"66%\"><span class=\"smalltext\"><strong><a href=\"{\$sorturl}&amp;sortby=subject&amp;order=asc\">{\$lang->thread}</a> {\$orderarrow['subject']} / <a href=\"{\$sorturl}&amp;sortby=starter&amp;order=asc\">{\$lang->author}</a> {\$orderarrow['starter']}</strong></span></td>")."#i", "<td class=\"tcat\" align=\"center\" colspan=\"3\" width=\"66%\"><span class=\"smalltext\"><strong><a href=\"{\$sorturl}&amp;sortby=subject&amp;order=asc\">{\$lang->thread}</a> {\$orderarrow['subject']}</strong></span></td>");
  find_replace_templatesets("forumdisplay_thread", "#".preg_quote("<td align=\"center\" class=\"{\$bgcolor}\"><a href=\"javascript:MyBB.whoPosted({\$thread['tid']});\">")."#i", "<td align=\"center\" class=\"{\$bgcolor}\">{\$classicauthorcolumn}</td>   <td align=\"center\" class=\"{\$bgcolor}\"><a href=\"javascript:MyBB.whoPosted({\$thread['tid']});\">");
  find_replace_templatesets("forumdisplay_threadlist", "#".preg_quote("<td class=\"tcat\" align=\"center\" width=\"7%\"><span class=\"smalltext\"><strong><a href=\"{\$sorturl}&amp;sortby=replies&amp;order=desc\">{\$lang->replies}</a>")."#i", "<td class=\"tcat\" align=\"center\" width=\"10%\"><span class=\"smalltext\"><strong><a href=\"{\$sorturl}&amp;sortby=starter&amp;order=asc\">{\$lang->author}</a> {\$orderarrow['starter']}</strong></span></td>   <td class=\"tcat\" align=\"center\" width=\"7%\"><span class=\"smalltext\"><strong><a href=\"{\$sorturl}&amp;sortby=replies&amp;order=desc\">{\$lang->replies}</a>");
}

function classicauthorcolumn_deactivate()
{
    require_once MYBB_ROOT."/inc/adminfunctions_templates.php";

  classicauthorcolumn_temp_uninstall("forumdisplay_threadlist", "#".preg_quote("9")."#i", "{\$colspan}");
  classicauthorcolumn_temp_uninstall("forumdisplay_threadlist", "#".preg_quote("9")."#i", "{\$colspan}");
  classicauthorcolumn_temp_uninstall("forumdisplay_thread", "#".preg_quote("<!-- authornamewashere -->")."#i", "<div class=\"author smalltext\">{\$classicauthorcolumn}</div>");
  classicauthorcolumn_temp_uninstall("forumdisplay_threadlist", "#".preg_quote("<td class=\"tcat\" align=\"center\" colspan=\"3\" width=\"66%\"><span class=\"smalltext\"><strong><a href=\"{\$sorturl}&amp;sortby=subject&amp;order=asc\">{\$lang->thread}</a> {\$orderarrow['subject']}  {\$orderarrow['starter']}</strong></span></td>")."#i", "<td class=\"tcat\" colspan=\"3\" width=\"66%\"><span class=\"smalltext\"><strong><a href=\"{\$sorturl}&amp;sortby=subject&amp;order=asc\">{\$lang->thread}</a> {\$orderarrow['subject']} / <a href=\"{\$sorturl}&amp;sortby=starter&amp;order=asc\">{\$lang->author}</a> {\$orderarrow['starter']}</strong></span></td>");
  classicauthorcolumn_temp_uninstall("forumdisplay_thread", "#".preg_quote("<td align=\"center\" class=\"{\$bgcolor}\">{\$classicauthorcolumn}</td>   <td align=\"center\" class=\"{\$bgcolor}\"><a href=\"javascript:MyBB.whoPosted({\$thread['tid']});\">")."#i", "<td align=\"center\" class=\"{\$bgcolor}\"><a href=\"javascript:MyBB.whoPosted({\$thread['tid']});\">");
  classicauthorcolumn_temp_uninstall("forumdisplay_threadlist", "#".preg_quote("<td class=\"tcat\" align=\"center\" width=\"10%\"><span class=\"smalltext\"><strong><a href=\"{\$sorturl}&amp;sortby=starter&amp;order=asc\">{\$lang->author}</a> {\$orderarrow['starter']}</strong></span></td>   <td class=\"tcat\" align=\"center\" width=\"7%\"><span class=\"smalltext\"><strong><a href=\"{\$sorturl}&amp;sortby=replies&amp;order=desc\">{\$lang->replies}</a>")."#i", "<td class=\"tcat\" align=\"center\" width=\"7%\"><span class=\"smalltext\"><strong><a href=\"{\$sorturl}&amp;sortby=replies&amp;order=desc\">{\$lang->replies}</a>");

}

function classicauthorcolumn_run()
{
     global $classicauthorcolumn, $thread, $db;
     $auid=$thread['uid'];
     $query=$db->query("SELECT * FROM ".TABLE_PREFIX."users WHERE uid=$auid LIMIT 1;");
     $record=$db->fetch_array($query);
     $classicauthorcolumn=build_profile_link(format_name($thread['username'], $record['usergroup'], $record['displaygroup']), $thread['uid']);
}


?>

I would strongly recommend to test the change thoroughly before uploading on an actual forum. Secondly, I added an extra query for each threadlist entry, as $thread doesn't seem to have a displaygroup entry.

If somebody else has a cleaner way to do this, please suggest.

Plus, this change needs reactivation of the plugin.