MyBB Community Forums

Full Version: Adding link to that pid in this code?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am using an Activity plugin to show last posts on a users profile, and when u click the thread link, instead of taking u directly to that users post, it will take u to the original thread.

In this code:
<h3 class="timeline-title"><a href="'.$threadlink.'" title="'.$threads[threadsubject].'">'.$threadsthreadsubject.'</a></h3>

How would I add the link to the post ID properly in here? I am currently editing a plugin and am unsure how to integrate that.

ThanksĀ  Smile
Bump if anyone can help!
You cannot just add pid to the link, the pid has to be queried within the plugin

something like

$query = $db->query("SELECT p.pid, p.fid, t.subject, t.tid FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."users u
ON (p.uid=u.uid)


then you may have to fetch query a pid link structure
$pid = (int)$activity['pid'];
		$link = get_post_link($pid."#pid".$pid, $tid);

then you'd need to build out the link

<h3 class="timeline-title"><a href="'.$link.'" title="'.$threads[threadsubject].'">'.$threadsthreadsubject.'</a></h3>


The only way to actually solve this is to look at the entire plugin itself. Unless you can figure it out from here, but let us know!
Thanks Michael. I tried doing as u said but couldn't seem to properly get it to work. The plugin contents:
<?php
/*
 * MyBB: Last User's Threads in Profile
 *
 * File: mybbirlastthreadsprofile.php
 *
 * Authors: AliReza_Tofighi & updated by Vintagedaddyo
 *
 * MyBB Version: 1.8
 *
 * Plugin Version: 1.2
 *
 */

// 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("member_profile_end", "mybbirlastthreadsprofile");


function mybbirlastthreadsprofile_info()
    {
    global $lang;

    $lang->load("mybbirlastthreadsprofile");

    $lang->mybbirlastthreadsprofile_Desc = '<form action="https://www.paypal.com/cgi-bin/webscr" method="post" style="float:right;">' .
        '<input type="hidden" name="cmd" value="_s-xclick">' .
        '<input type="hidden" name="hosted_button_id" value="AZE6ZNZPBPVUL">' .
        '<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">' .
        '<img alt="" border="0" src="https://www.paypalobjects.com/pl_PL/i/scr/pixel.gif" width="1" height="1">' .
        '</form>' . $lang->mybbirlastthreadsprofile_Desc;

    return Array(
        'name' => $lang->mybbirlastthreadsprofile_Name,
        'description' => $lang->mybbirlastthreadsprofile_Desc,
        'website' => $lang->mybbirlastthreadsprofile_Web,
        'author' => $lang->mybbirlastthreadsprofile_Auth,
        'authorsite' => $lang->mybbirlastthreadsprofile_AuthSite,
        'version' => $lang->mybbirlastthreadsprofile_Ver,
        'compatibility' => $lang->mybbirlastthreadsprofile_Compat
    );
    }


function mybbirlastthreadsprofile_activate(){
	global $mybb, $db;
	include MYBB_ROOT."/inc/adminfunctions_templates.php";
	find_replace_templatesets("member_profile", "#".preg_quote('{$mybbirlastthreadsprofile}')."#i", '', 0);
	find_replace_templatesets("member_profile", "#".preg_quote('{$signature}')."#i", '{$mybbirlastthreadsprofile}{$signature}');
}

function mybbirlastthreadsprofile_deactivate(){
	global $mybb, $db;
	include MYBB_ROOT."/inc/adminfunctions_templates.php";
	find_replace_templatesets("member_profile", "#".preg_quote('{$mybbirlastthreadsprofile}')."#i", '', 0);

}


function mybbirlastthreadsprofile()
{
	global $db, $mybb, $memprofile, $theme, $lang, $mybbirlastthreadsprofile, $parser;

    $lang->load("mybbirlastthreadsprofile");

	$threadlimit = 5;
	$query = $db->query("
		SELECT t.*, p.*, u.username, u.usergroup, u.displaygroup, f.name AS forumname
		FROM ".TABLE_PREFIX."posts p	
		LEFT JOIN ".TABLE_PREFIX."users u ON (p.username=u.username)
		LEFT JOIN ".TABLE_PREFIX."forums f ON (p.fid=f.fid)
		LEFT JOIN ".TABLE_PREFIX."threads t ON (p.tid=t.tid)
		WHERE p.visible = '1' And p.uid = '{$memprofile['uid']}'
		ORDER BY p.pid DESC, p.dateline DESC
		LIMIT 0, {$threadlimit}
	");

	while($threads = $db->fetch_array($query))
	{

        $threads['subject'] = htmlspecialchars_uni($threads['subject']);

		if(strlen($threads['subject']) > "40")
		{
			$threadsthreadsubject = my_substr($threads['subject'],0,40)."...";
		}
		else
		{
			$threadsthreadsubject = $threads['subject'];
		}

		if(strlen($threads['forumname']) > "20")
		{
			$threadsforumname = my_substr($threads['forumname'],0,20)."...";
		}
		else
		{
			$threadsforumname = $threads['forumname'];
		}
		
		$parser_options = array(
			'allow_html' => 1,
			'allow_mycode' => 1,
			'allow_smilies' => 1,
			'allow_imgcode' => 1,
			'allow_videocode' => 1,
			'filter_badwords' => 1,
		);
		
		$post_message = $parser->parse_message($threads['message'], $parser_options);
		$emptyArray = [];
$postmessage = hidecontent_parse_tags($emptyArray, true, $post_message, true);
		
		if(strlen($postmessage) > "300")
		{
			$threadreadmore = '<div class="panel-wrapper" id="item-'.$threads[pid].'" style="height: 80px;overflow: hidden;;"><p>'.$postmessage.'</p></div><div style="display: flex"><a class="readmore" href="javascript://" id="'.$threads[pid].'">Read More </a></div>';
		}
		else
		{
			$threadreadmore = '<div class="panel-wrapper" id="item-'.$threads[pid].'"><p>'.$postmessage.'</p></div>';
		}
	
		$threadlink = get_thread_link($threads['tid']);
		$forumlink = get_forum_link($threads['fid']);
		$replies = my_number_format($threads['replies']);
		$views = my_number_format($threads['views']);
		$lastpostdate = my_date($mybb->settings['dateformat'], $threads['dateline']);
		$lastposttime = my_date($mybb->settings['timeformat'], $threads['dateline']);
		$lastposter = format_name(htmlspecialchars_uni($threads['username']), $threads['usergroup'], $threads['displaygroup']);
		$lastposter = build_profile_link($lastposter, $threads['lastposteruid']);

		$last_thread .= '
		<li class="timeline-item">
			<div class="timeline-info">
				<span><i class="fas fa-clock"></i> '.$lastposttime.'&nbsp;&nbsp;'.$lastpostdate.'&nbsp;&nbsp;&nbsp;&nbsp;<i class="fas fa-comments-alt"></i> '.$replies.' posts</span>
			</div>
			<div class="timeline-marker"></div>
			<div class="timeline-content">
			<div>
				<h3 class="timeline-title"><a href="'.$threadlink.'" title="'.$threads[threadsubject].'">'.$threadsthreadsubject.'</a></h3>	
				'.$threadreadmore.'
				<script>
					$(function(){
					var $allItems =  $(".panel-wrapper");
					$(document.body).on("click", "a.readmore", function () {
						var id = this.id, itemId = "#item-" + id;
						$allItems.not($(itemId).toggleClass("active"));
					});
					});
				</script>
				<style>
					.panel-wrapper.active{
						height: 100% !important;
					}
					.readmore {
						background: #2c2c2c;
						padding: 5px 12px 7px;
						margin-top: 10px;
						color: #a4a4a4;
						border-radius: 3px;
					}
					.readmore:hover {
						background: #a92f2f;
						color: #efefef;
					}
				</style>			
			</div><h4><br /> - <a href="'.$forumlink.'">'.$threads[forumname].'</a> - </h4>
			</div>
		</li>';

	}
	if(!$last_thread){
    global $lang;

    $lang->load("mybbirlastthreadsprofile");

		$last_thread = "<div class=\"activity-split trow1\" style=\"margin: auto; float: none;padding: 25px;\">No content</div><br />";
	}

	global $lang;

    $lang->load("mybbirlastthreadsprofile");

	$mybbirlastthreadsprofile = "<div class=\"activity-split trow1\" style=\"margin: auto; float: none;padding: 25px;\"><ul class=\"timeline\"><!-- change timeline-split to timeline or timeline-centered, to change the timeline style -->{$last_thread}</ul></div><br />";
}
?>
Okay but MAKE SURE TO Save a copy of your last version, in case this does not work. If there is an error, tell me what the error is, then revert to your last version.

but try this and see if it works. Just overwrite and click save. Go to profile and see if the changes are what you expect

<?php
/*
 * MyBB: Last User's Threads in Profile
 *
 * File: mybbirlastthreadsprofile.php
 *
 * Authors: AliReza_Tofighi & updated by Vintagedaddyo
 *
 * MyBB Version: 1.8
 *
 * Plugin Version: 1.2
 *
 */

// 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("member_profile_end", "mybbirlastthreadsprofile");


function mybbirlastthreadsprofile_info()
    {
    global $lang;

    $lang->load("mybbirlastthreadsprofile");

    $lang->mybbirlastthreadsprofile_Desc = '<form action="https://www.paypal.com/cgi-bin/webscr" method="post" style="float:right;">' .
        '<input type="hidden" name="cmd" value="_s-xclick">' .
        '<input type="hidden" name="hosted_button_id" value="AZE6ZNZPBPVUL">' .
        '<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">' .
        '<img alt="" border="0" src="https://www.paypalobjects.com/pl_PL/i/scr/pixel.gif" width="1" height="1">' .
        '</form>' . $lang->mybbirlastthreadsprofile_Desc;

    return Array(
        'name' => $lang->mybbirlastthreadsprofile_Name,
        'description' => $lang->mybbirlastthreadsprofile_Desc,
        'website' => $lang->mybbirlastthreadsprofile_Web,
        'author' => $lang->mybbirlastthreadsprofile_Auth,
        'authorsite' => $lang->mybbirlastthreadsprofile_AuthSite,
        'version' => $lang->mybbirlastthreadsprofile_Ver,
        'compatibility' => $lang->mybbirlastthreadsprofile_Compat
    );
    }


function mybbirlastthreadsprofile_activate(){
	global $mybb, $db;
	include MYBB_ROOT."/inc/adminfunctions_templates.php";
	find_replace_templatesets("member_profile", "#".preg_quote('{$mybbirlastthreadsprofile}')."#i", '', 0);
	find_replace_templatesets("member_profile", "#".preg_quote('{$signature}')."#i", '{$mybbirlastthreadsprofile}{$signature}');
}

function mybbirlastthreadsprofile_deactivate(){
	global $mybb, $db;
	include MYBB_ROOT."/inc/adminfunctions_templates.php";
	find_replace_templatesets("member_profile", "#".preg_quote('{$mybbirlastthreadsprofile}')."#i", '', 0);

}


function mybbirlastthreadsprofile()
{
	global $db, $mybb, $memprofile, $theme, $lang, $mybbirlastthreadsprofile, $parser;

    $lang->load("mybbirlastthreadsprofile");

	$threadlimit = 5;
	$query = $db->query("
		SELECT t.*, p.*, u.username, p.pid, p.fid, u.usergroup, u.displaygroup, f.name AS forumname
		FROM ".TABLE_PREFIX."posts p	
		LEFT JOIN ".TABLE_PREFIX."users u ON (p.username=u.username)
		LEFT JOIN ".TABLE_PREFIX."forums f ON (p.fid=f.fid)
		LEFT JOIN ".TABLE_PREFIX."threads t ON (p.tid=t.tid)
			LEFT JOIN ".TABLE_PREFIX."users u
		ON (p.uid=u.uid)
		WHERE p.visible = '1' And p.uid = '{$memprofile['uid']}'
		ORDER BY p.pid DESC, p.dateline DESC
		LIMIT 0, {$threadlimit}
	");
	
	while($threads = $db->fetch_array($query))
	{

        $threads['subject'] = htmlspecialchars_uni($threads['subject']);

		if(strlen($threads['subject']) > "40")
		{
			$threadsthreadsubject = my_substr($threads['subject'],0,40)."...";
		}
		else
		{
			$threadsthreadsubject = $threads['subject'];
		}

		if(strlen($threads['forumname']) > "20")
		{
			$threadsforumname = my_substr($threads['forumname'],0,20)."...";
		}
		else
		{
			$threadsforumname = $threads['forumname'];
		}
		
		$parser_options = array(
			'allow_html' => 1,
			'allow_mycode' => 1,
			'allow_smilies' => 1,
			'allow_imgcode' => 1,
			'allow_videocode' => 1,
			'filter_badwords' => 1,
		);
		
		$post_message = $parser->parse_message($threads['message'], $parser_options);
		$emptyArray = [];
$postmessage = hidecontent_parse_tags($emptyArray, true, $post_message, true);
		
		if(strlen($postmessage) > "300")
		{
			$threadreadmore = '<div class="panel-wrapper" id="item-'.$threads[pid].'" style="height: 80px;overflow: hidden;;"><p>'.$postmessage.'</p></div><div style="display: flex"><a class="readmore" href="javascript://" id="'.$threads[pid].'">Read More </a></div>';
		}
		else
		{
			$threadreadmore = '<div class="panel-wrapper" id="item-'.$threads[pid].'"><p>'.$postmessage.'</p></div>';
		}
		
	    $pid = (int)$mybbirlastthreadsprofile['pid'];
		$link = get_post_link($pid."#pid".$pid, $tid);
		$threadlink = get_thread_link($threads['tid']);
		$forumlink = get_forum_link($threads['fid']);
		$replies = my_number_format($threads['replies']);
		$views = my_number_format($threads['views']);
		$lastpostdate = my_date($mybb->settings['dateformat'], $threads['dateline']);
		$lastposttime = my_date($mybb->settings['timeformat'], $threads['dateline']);
		$lastposter = format_name(htmlspecialchars_uni($threads['username']), $threads['usergroup'], $threads['displaygroup']);
		$lastposter = build_profile_link($lastposter, $threads['lastposteruid']);

		$last_thread .= '
		<li class="timeline-item">
			<div class="timeline-info">
				<span><i class="fas fa-clock"></i> '.$lastposttime.'&nbsp;&nbsp;'.$lastpostdate.'&nbsp;&nbsp;&nbsp;&nbsp;<i class="fas fa-comments-alt"></i> '.$replies.' posts</span>
			</div>
			<div class="timeline-marker"></div>
			<div class="timeline-content">
			<div>
				<h3 class="timeline-title"><a href="'.$link.'" title="'.$threads[threadsubject].'">'.$threadsthreadsubject.'</a></h3>	
				'.$threadreadmore.'
				<script>
					$(function(){
					var $allItems =  $(".panel-wrapper");
					$(document.body).on("click", "a.readmore", function () {
						var id = this.id, itemId = "#item-" + id;
						$allItems.not($(itemId).toggleClass("active"));
					});
					});
				</script>
				<style>
					.panel-wrapper.active{
						height: 100% !important;
					}
					.readmore {
						background: #2c2c2c;
						padding: 5px 12px 7px;
						margin-top: 10px;
						color: #a4a4a4;
						border-radius: 3px;
					}
					.readmore:hover {
						background: #a92f2f;
						color: #efefef;
					}
				</style>			
			</div><h4><br /> - <a href="'.$forumlink.'">'.$threads[forumname].'</a> - </h4>
			</div>
		</li>';

	}
	if(!$last_thread){
    global $lang;

    $lang->load("mybbirlastthreadsprofile");

		$last_thread = "<div class=\"activity-split trow1\" style=\"margin: auto; float: none;padding: 25px;\">No content</div><br />";
	}

	global $lang;

    $lang->load("mybbirlastthreadsprofile");

	$mybbirlastthreadsprofile = "<div class=\"activity-split trow1\" style=\"margin: auto; float: none;padding: 25px;\"><ul class=\"timeline\"><!-- change timeline-split to timeline or timeline-centered, to change the timeline style -->{$last_thread}</ul></div><br />";
}
?>

Ah, maybe there is no need for the above plugin edit, just try this first, just use this code below, and see if that is all you need to do,

if the below simple solution does not work, then try the plugin edit I provided


<h3 class="timeline-title"><a href="'.$threads[pid].'" title="'.$threads[threadsubject].'">'.$threadsthreadsubject.'</a></h3>
This line is missing thread link, but I think it will work when added. What would be the way to add it in?

<h3 class="timeline-title"><a href="'.$threads[pid].'" title="'.$threads[threadsubject].'">'.$threadsthreadsubject.'</a></h3>

The above code as well that you added did not seem to work, but I think the line will work once thread link is added as it shows the post ID number, but it won't add thread link. For example: mydomain.com/92093 (92093 = Post ID)

Edit: Did this and it worked:

<h3 class="timeline-title"><a href="'.$threadlink.'#pid'.$threads[pid].'" title="'.$threads[threadsubject].'">'.$threadsthreadsubject.'</a></h3>
(2020-01-01, 11:59 PM)makpaolo Wrote: [ -> ]This line is missing thread link, but I think it will work when added. What would be the way to add it in?

<h3 class="timeline-title"><a href="'.$threads[pid].'" title="'.$threads[threadsubject].'">'.$threadsthreadsubject.'</a></h3>

The above code as well that you added did not seem to work, but I think the line will work once thread link is added as it shows the post ID number, but it won't add thread link. For example: mydomain.com/92093 (92093 = Post ID)

Edit: Did this and it worked:

<h3 class="timeline-title"><a href="'.$threadlink.'#pid'.$threads[pid].'" title="'.$threads[threadsubject].'">'.$threadsthreadsubject.'</a></h3>

Awesome man! I knew we could get it working for you.