MyBB Community Forums

Full Version: Postbit $post variable not storing value
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4
I'm trying to display the $post['output'] variable in the postbit from the postbit hook, but nothing is being displayed. I am using the following:
find_replace_templatesets("postbit_author_user", "#".preg_quote('{$post[\'userregdate\']}</div>')."#i", "{\$post['userregdate']}</div>\n<div class=\"post_userdetails\">{\$post['output']}</div>");

It creates the little box from the post_userdetails class, but there is no value in $post['output'] when there should be from the following code:
function currentactivity_postbit(&$post) {
	global $templates, $db, $mybb;
	
	$getPostUser = $db->simple_select("posts", "*", "pid='" . $post['pid'] . "'");
	$user = $db->fetch_array($getPostUser);
	$query = $db->simple_select("current_activity", "*", "uid='" . $user['uid'] . "'");
	$array = $db->fetch_array($query);
	if ($db->num_rows($query) == 1) {
		if ($array['current_act'] == "Listening") {
			$post['output'] = "Currently {$array['current_act']} to: {$array['current_obj']}";
			//$post['output'] = "<div class=\"post_userdetails\"><label>Currently {$array['current_act']} to: {$array['current_obj']}</label></div>";
		} else {
			$post['output'] = "Currently {$array['current_act']}: {$array['current_obj']}";
			//$post['output'] = "<div class=\"post_userdetails\"><label>Currently {$array['current_act']}: {$array['current_obj']}</label></div>";
		}
	} else {
		$post['output'] = "Currently Playing: ???";
		//$post['output'] = "<div class=\"post_userdetails\"><label>Current Playing: ???</label></div>";
	}	
}

Any help is appreciated.

Regards,
Shannon
Using $post['output'] in postbit or postbit_classic templates doesn´t works?

It will not work on postbit_author_user since that tempalte get eval´d before the hook is ran.
It will work if you follow the Omar's post's first part.

However if you want to use postbit_author_user for some reason then you've to use it something like this;
function currentactivity_postbit(&$post) {
    global $templates, $db, $mybb;
    
    $getPostUser = $db->simple_select("posts", "*", "pid='" . $post['pid'] . "'");
    $user = $db->fetch_array($getPostUser);
    $query = $db->simple_select("current_activity", "*", "uid='" . $user['uid'] . "'");
    $array = $db->fetch_array($query);
    if ($db->num_rows($query) == 1) {
        if ($array['current_act'] == "Listening") {
            $post['output'] = "Currently {$array['current_act']} to: {$array['current_obj']}";
            //$post['output'] = "<div class=\"post_userdetails\"><label>Currently {$array['current_act']} to: {$array['current_obj']}</label></div>";
        } else {
            $post['output'] = "Currently {$array['current_act']}: {$array['current_obj']}";
            //$post['output'] = "<div class=\"post_userdetails\"><label>Currently {$array['current_act']}: {$array['current_obj']}</label></div>";
        }
    } else {
        $post['output'] = "Currently Playing: ???";
        //$post['output'] = "<div class=\"post_userdetails\"><label>Current Playing: ???</label></div>";
    }
	
	$post['user_details'].= $post['user_details'].'<br />'.$post['output'];
}
Using something like str_repalce() could be the best option if you want to use it in the postbit_author_user template.
I still don't know what you mean. Shouldn't I be able to treat it exactly the same?
The template "postbit_author_user" is evaluated before the hooks is run, so unless you use it on "postbit" or "postbit_classic" you will need to use some replacement function to make it to work.
Shannon: Have you tried the suggestion I posted above ??
Yes, I tried that Yaldaram. It doesn't seem to work. Is there another way?
Shannon, I activated the plugin on the website to see what it looked like in action. In classic view, it is displaying the "Currently" text, just not in the right place (yet). Is there something that you're doing differently in that template? Maybe therein lies your answer.

The vertical post_bit still isn't displaying anything, however. Perhaps Tecca can offer some advice, since he designed the theme. Try contacting him?
For some reason, Tecca uses the postbit_author_user template to display user details, but it doesn't work with the method I want to use. I'll just wait for more insight from Yaldaram etc.
Pages: 1 2 3 4