MyBB Community Forums

Full Version: Display on member.php
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
I asked MyBB staff and they said it's best to eval.
Yes, eval your variable and then str_replace a string in "member_profile_customfields" with the outcome.

Just what I told you here:
http://community.mybb.com/thread-122087-...#pid882701

Hook at member_profile_end
Should it be looking like this then?

function currentactivity_profile() {
    global $templates, $member_current_act, $db, $memprofile;
    
    $getUser = $db->simple_select("current_activity", "*", "uid='" . intval($memprofile['uid']) . "'");
    $userArray = $db->fetch_array($getUser);
    
    eval("\$member_current_act = \"".$templates->get('currentactivity_profile')."\";"); 
	str_replace("\{$curract}", $userArray['currentAct'], "\{$customfields}");
	str_replace("\{$currobj}", $userArray['currentObj'], "\{$customfields}");
}
You need $profilefields to replace a string (in this case "<!--act-->") with your variable:
function currentactivity_profile() {
    global $templates, $member_current_act, $db, $memprofile, $profilefields;
    
    $getUser = $db->simple_select("current_activity", "*", "uid='" . intval($memprofile['uid']) . "'");
    $userArray = $db->fetch_array($getUser);
    
    eval("\$member_current_act = \"".$templates->get('currentactivity_profile')."\";"); 
    $profilefields = str_replace('<!--act-->', $member_current_act, $profilefields);
} 

Add "<!--act-->" into your "member_profile_customfields" template.

You don't need to global $member_current_act .
What do you mean? Also, what's the square bracket after $member_current_act? I'll try this now.
A mistake in my code Toungue, remove the bracket.

$member_current_act is not used outside the function, so you don't need it as a global.
Well, it's not working. The <!--act--> and <!--obj--> need to be replace by something from the database (hence the query, and array fetch).

<?php
if (!defined("IN_MYBB")) {
    die("Direct initialisation of the script is not permitted.");
}

$plugins->add_hook("usercp_profile_start", "currentactivity_options");
$plugins->add_hook("usercp_do_profile_start", "currentactivity_do_profile");
$plugins->add_hook("postbit", "currentactivity_postbit");
$plugins->add_hook("member_profile_end", "currentactivity_profile");

function currentactivity_info() {
    return array(
        "name" => "Current Activity",
        "description" => "Lists the current activity of a user on their profile and in the postbit.",
        "website" => "http://jrpgclub.com/community",
        "author" => "Shannon Rothe",
        "authorsite" => "http://jrpgclub.com/community",
        "version" => "1.6.8"
    );
}

function currentactivity_activate() {
    global $db, $mybb, $current_act, $current_postbit;
	if (!$db->table_exists("current_activity")) {
		$query = $db->write_query("CREATE TABLE " . TABLE_PREFIX . "current_activity (
								id INT AUTO_INCREMENT PRIMARY KEY,
								uid INT,
								current_act VARCHAR(65),
								current_obj VARCHAR(65)
							)");
	}
                        
    $template = array(
        "title" => $db->escape_string('currentactivity_options'),
        "template" => $db->escape_string('<tr>
											<td>
												<label>Currently: </label>
											</td>
										</tr>
											<td>
												<select name="currently" id="currently">
													<option value="Watching">Watching</option>
													<option value="Playing">Playing</option>
													<option value="Listening">Listening to</option>
													<option value="Reading">Reading</option>
												</select>
												<input name="obj" type="text" id="obj">
											</td>
										</tr>
										'),
        "sid"        => -1,
        "version"    => 1608,
        "dateline"    => TIME_NOW
    );
	
	$member_template = array(
		"title" => $db->escape_string('currentactivity_profile'),
		"template" => $db->escape_string('<tr>
											<td class="trow2" width="40%">
												<strong>Currently:</strong>
											</td>
											<td class="trow2" width="60%">
												<!--act--> <!--obj-->
											</td>
										</tr>'),
		"sid" => -1,
		"version" => 1608,
		"dateline" => TIME_NOW
	);
	
	$db->insert_query("templates", $template);
	$db->insert_query("templates", $member_template);
	
    require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
    find_replace_templatesets("usercp_profile_profilefields", "#".preg_quote('{$customfields}')."#i", "{\$customfields}\n{\$current_act}");
	find_replace_templatesets("postbit_author_user", "#".preg_quote('{$post[\'userregdate\']}</div>')."#i", "{\$post['userregdate']}</div>\n<!--OUTPUT-->");
	find_replace_templatesets("member_profile_customfields", "#".preg_quote('{$customfields}')."#i", "{\$customfields}\n{\$member_current_act}");
	//find_replace_templatesets("postbit", "#".preg_quote('{$post[\'user_details\']}')."#i", "{\$post['user_details']}\n{\$post['output']}");
	//find_replace_templatesets("postbit_classic", "#".preg_quote('{$post[\'user_details\']}')."#i", "{\$post['user_details']}\n{\$post['output']}");
}

function currentactivity_deactivate() {
    global $db, $current_act, $current_postbit;
	if ($db->table_exists(TABLE_PREFIX . "current_activity")) {
		$query = $db->write_query("DROP TABLE " . TABLE_PREFIX . "current_activity");
	}
	$post['output'] = "";
	
	$db->delete_query("templates", "title='currentactivity_options'");
	$db->delete_query("templates", "title='currentactivity_profile'");
	
	require_once MYBB_ROOT."inc/adminfunctions_templates.php";
    find_replace_templatesets("usercp_profile_profilefields", '#'.preg_quote('{$current_act}').'#', '',0);
	//find_replace_templatesets("postbit", '#'.preg_quote('{$post[\'output\']}').'#', '', 0);
	find_replace_templatesets("postbit_author_user", '#'.preg_quote('<!--OUTPUT-->').'#', '', 0);
	find_replace_templatesets("member_profile_customfields", '#'.preg_quote('{$member_current_act}').'#', '', 0);
	//find_replace_templatesets("postbit_classic", '#'.preg_quote('{$post[\'output\']}').'#', '', 0);
}

function currentactivity_options() {
    global $templates, $current_act;
    eval("\$current_act = \"".$templates->get('currentactivity_options')."\";"); 
}

function currentactivity_do_profile() {
	global $mybb, $db;
	
	$currently = $db->escape_string(trim($mybb->input['currently']));
	$obj = $db->escape_string(trim($mybb->input['obj']));
	$obj = htmlspecialchars_uni($obj);
	
	$getUser = $db->simple_select("current_activity", "*", "uid='" . $mybb->user['uid'] . "'");
	if ($db->num_rows($getUser) == 1) {
		$db->update_query("current_activity", array("current_act" => "{$currently}", "current_obj" => "{$obj}"), "uid='" . $mybb->user['uid'] . "'");
	} else {
		$db->insert_query("current_activity", array("uid" => "{$mybb->user['uid']}", "current_act" => "{$currently}", "current_obj" => "{$obj}"));
	}
}

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: <br />{$array['current_obj']}";
		} else {
			$post['output'] = "Currently {$array['current_act']}: <br />{$array['current_obj']}";
		}
	} else {
		$post['output'] = "Currently Playing: ???";
	}
	$post['user_details'] = str_replace('<!--OUTPUT-->', "<div class=\"post_userdetails\">".$post['output']."</div>",  $post['user_details']); 	
}

function currentactivity_profile() {
    global $templates, $member_current_act, $db, $memprofile, $profilefields;
    
    $getUser = $db->simple_select("current_activity", "*", "uid='" . intval($memprofile['uid']) . "'");
    $userArray = $db->fetch_array($getUser);
    
    eval("\$member_current_act = \"".$templates->get('currentactivity_profile')."\";"); 
	$profilefields = str_replace("<!--act-->", $member_current_act, $profilefields);
	//$profilefields = str_replace("<!--obj-->", $member_current_act, $profilefields);
} 

Nothing is even displayed in the member profile from this code.
Everything you put in your "currentactivity_profile" template will replace "<!--act-->" in the "member_profile_customfields" template.
I'm so confused. In my template:
$member_template = array(
		"title" => $db->escape_string('currentactivity_profile'),
		"template" => $db->escape_string('<tr>
											<td class="trow2" width="40%">
												<strong>Currently:</strong>
											</td>
											<td class="trow2" width="60%">
												<!--act--> <!--obj-->
											</td>
										</tr>'),
		"sid" => -1,
		"version" => 1608,
		"dateline" => TIME_NOW
	);

I need to replace the <!--act--> and <!--obj--> in it with values from the database, which are the queries in the currentactivity_profile function.
You can user your template normally, where you need to apply the str_replace is in the member_profile_customfields template.
Pages: 1 2 3