2012-07-11, 04:01 AM
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:
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')."\";");
}