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'm trying to add a custom field, via plugin on the member.php (profile) page and to do so I'm hooking to member_profile_start. In the activation of the plugin, I send a template to the templates table, and then when the hooked function is called, the variable I set in the member_profile_customfields is eval'd as the template in the database. However, I'm getting no output what so ever.

This is the code:
<?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_start", "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(TABLE_PREFIX . "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%">
												{$userArray[\'current_act\']} {$userArray[\'current_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;
	
	$getUser = $db->simple_select("current_activity", "*", "uid='" . $db->escape_string($mybb->input['uid']) . "'");
	$userArray = $db->fetch_array($getUser);
	
	eval("\$member_current_act = \"".$templates->get('currentactivity_profile')."\";"); 
}
Hook into the member_profile_end hook and Change the function to this;
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')."\";"); 
}
Alright I did that Yaldaram, but now nothing is displaying on the member.php page. Any more ideas?
There is issue in writing the query for the new table as well.

This line;
if ($db->table_exists(TABLE_PREFIX . "current_activity")) {
Should be like this;
if (!$db->table_exists("current_activity")) {
Alright, I fixed that. It's still not displaying anything in the member profile page though. What do you think the problem is Yaldaram?
Can anybody help me further? It would be greatly appreciated. Smile
Which template you want to use your variable in? Sorry if I don't get it from your previous posts.
Well it will be the member_profile_customfields template. Smile
Try using str_replace().
Yes, just what Nervo told in the previous thread, str_replace() is a nice function to do jobs like these.
Pages: 1 2 3