2020-09-15, 11:00 PM
Honestly, it should be, but, I cannot 100% guarentee that it is. But it *should* be.
Here is the threadlog.php file, though:
Here is the threadlog.php file, though:
<?php
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.");
}
function threadlog_info()
{
return array(
"name" => "Threadlog",
"description" => "Creates a threadlog for users",
"website" => "http://autumnwelles.com/",
"author" => "Autumn Welles",
"authorsite" => "http://autumnwelles.com/",
"version" => "3.0",
"guid" => "",
"codename" => "threadlog",
"compatibility" => "18*"
);
}
function threadlog_install()
{
global $db, $mybb;
// alter the forum table
$db->write_query("ALTER TABLE `". $db->table_prefix ."forums` ADD `threadlog_include` TINYINT( 1 ) NOT NULL DEFAULT '0'");
// SETTINGS
// make a settings group
$setting_group = array(
'name' => 'threadlog_settings',
'title' => 'Threadlog Settings',
'description' => 'Modify settings for the threadlog plugin.',
'disporder' => 5,
'isdefault' => 0,
);
// get the settings group ID
$gid = $db->insert_query("settinggroups", $setting_group);
// define the settings
$settings_array = array(
'threadlog_perpage' => array(
'title' => 'Threads per page',
'description' => 'Enter the number of threads that should display per page.',
'optionscode' => 'text',
'value' => 50,
'disporder' => 2,
),
);
// add the settings
foreach($settings_array as $name => $setting)
{
$setting['name'] = $name;
$setting['gid'] = $gid;
$db->insert_query('settings', $setting);
}
// rebuild
rebuild_settings();
// TEMPLATES
// define the page template
$threadlog_page = '<html>
<head>
<title>{$mybb->settings[\'bbname\']} - {$username}\'s Threadlog</title>
{$headerinclude}
</head>
<body>
{$header}
{$multipage}
<table id="threadlog" class="tborder" border="0" cellpadding="{$theme[\'tablespace\']}" cellspacing="{$theme[\'borderwidth\']}">
<thead>
<tr>
<td class="thead" colspan="4">{$username}\'s Threadlog · <a href="{$mybb->settings[\'bburl\']}/member.php?action=profile&uid={$uid}">View Profile</a></td>
</tr>
<tr>
<td class="tcat">Thread</td>
<td class="tcat" align="center">Participants</td>
<td class="tcat" align="center">Posts</td>
<td class="tcat" align="right">Last Post</td>
</tr>
</thead>
<tbody>
{$threadlog_list}
</tbody>
<tfoot>
<tr><td class="tfoot" colspan="4" align="center">
<a href="#" id="active">{$count_active} active</a> ·
<a href="#" id="closed">{$count_closed} closed</a> ·
<a href="#" id="need-replies">{$count_replies} need replies</a> ·
<a href="#" id="show-all">{$count_total} total</a>
</td></tr>
</tfoot>
</table>
{$multipage}
{$footer}
<script type="text/javascript" src="{$mybb->settings[\'bburl\']}/inc/plugins/threadlog/threadlog.js"></script>
</body>
</html>';
// create the page template
$insert_array = array(
'title' => 'threadlog_page',
'template' => $db->escape_string($threadlog_page),
'sid' => '-1',
'version' => '',
'dateline' => time(),
);
// insert the page template into DB
$db->insert_query('templates', $insert_array);
// define the row template
$threadlog_row = '<tr class="{$thread_status}"><td class="{$thread_row}">{$thread_prefix} {$thread_title}<div class="smalltext">on {$thread_date}</small></td>
<td class="{$thread_row}" align="center">{$thread_participants}</td>
<td class="{$thread_row}" align="center"><a href="javascript:MyBB.whoPosted({$tid});">{$thread_posts}</a></td>
<td class="{$thread_row}" align="right">Last post by {$thread_latest_poster}<div class="smalltext">on {$thread_latest_date}</div></td></tr>';
// create the row template
$insert_array = array(
'title' => 'threadlog_row',
'template' => $db->escape_string($threadlog_row),
'sid' => '-1',
'version' => '',
'dateline' => time(),
);
// insert the list row into DB
$db->insert_query('templates', $insert_array);
// define the row template
$threadlog_nothreads = "<tr><td colspan='4'>No threads to speak of.</td></tr>";
// create the row template
$insert_array = array(
'title' => 'threadlog_nothreads',
'template' => $db->escape_string($threadlog_nothreads),
'sid' => '-1',
'version' => '',
'dateline' => time(),
);
// insert the list row into DB
$db->insert_query('templates', $insert_array);
}
function threadlog_is_installed()
{
global $db, $mybb;
if($db->field_exists("threadlog_include", "forums") &&
isset($mybb->settings['threadlog_perpage'])) {
return true;
}
return false;
}
function threadlog_uninstall()
{
global $db;
// delete forum option
$db->write_query("ALTER TABLE `". $db->table_prefix ."forums` DROP `threadlog_include`;");
// delete settings
$db->delete_query('settings', "name IN ('threadlog_perpage')");
// delete settings group
$db->delete_query('settinggroups', "name = 'threadlog_settings'");
// delete templates
$db->delete_query("templates", "title IN ('threadlog_page','threadlog_row','threadlog_nothreads')");
// rebuild
rebuild_settings();
}
function threadlog_activate()
{
}
function threadlog_deactivate()
{
}
// this is the main beef, right here
$plugins->add_hook('misc_start', 'threadlog');
function threadlog()
{
global $mybb, $templates, $theme, $lang, $header, $headerinclude, $footer, $uid, $tid;
global $threadfields;
// show the threadlog when we call it
if($mybb->get_input('action') == 'threadlog')
{
global $mybb, $db, $templates;
$templatelist = "multipage,multipage_end,multipage_jump_page,multipage_nextpage,multipage_page,multipage_page_current,multipage_page_link_current,multipage_prevpage,multipage_start";
// check for a UID
if(isset($mybb->input['uid']))
{
$uid = intval($mybb->input['uid']);
}
// if no UID, show logged in user
elseif(isset($mybb->user['uid']))
{
$uid = $mybb->user['uid'];
}
else
{
exit;
}
// get the username and UID of current user
$userquery = $db->simple_select('users', 'uid, username, usergroup, displaygroup', 'uid = '. $uid .'');
$user_data = $db->fetch_array($userquery);
isset($user_data['uid']) || error('Invalid user.');
$username = htmlspecialchars_uni($user_data['username']);
$username_formatted = format_name($username, $user_data['usergroup'], $user_data['displaygroup']);
// add the breadcrumb
add_breadcrumb($username .'\'s Threadlog', "misc.php?action=threadlog");
// set up this variable, idk why?
$threads = "";
// get threads that this user participated in
$query = $db->simple_select("posts", "DISTINCT tid", "uid = ".$uid."");
$topics = "";
// build our topic list
while($row = $db->fetch_array($query))
{
$topics .= $row['tid'] .",";
}
// remove last comma
$topics = substr_replace($topics, "", -1);
// set up topics query
if(isset($topics))
{
$tids = " AND tid IN ('". str_replace(',', '\',\'', $topics) ."')";
}
else
{
$tids = "";
}
// get the list of forums to include
$query = $db->simple_select("forums", "fid", "threadlog_include = 1");
if($db->num_rows($query) < 1)
{
$forum_select = " ";
}
else
{
$i = 0;
while($forum = $db->fetch_array($query)) {
$i++;
if ($i > 1) {
$fids .= ",'". $forum['fid'] ."'";
} else {
$fids .= "'". $forum['fid'] ."'";
}
}
$forum_select = " AND fid IN(". $fids .")";
}
// set up the pager
$threadlog_url = htmlspecialchars_uni("misc.php?action=threadlog&uid=". $uid);
$per_page = intval($mybb->settings['threadlog_perpage']);
$page = $mybb->get_input('page', MyBB::INPUT_INT);
if($page && $page > 0)
{
$start = ($page - 1) * $per_page;
}
else
{
$start = 0;
$page = 1;
}
$page_total = 0;
$query = $db->simple_select("threads", "COUNT(*) AS threads", "visible = 1". $tids . $forum_select);
$threadlog_total = $db->fetch_field($query, "threads");
$count_total = $threadlog_total; // getting the total here, since it's convenient
$multipage = multipage($threadlog_total, $per_page, $page, $threadlog_url);
// get replies total
$query = $db->simple_select("threads", "tid", "visible = 1 AND `closed` != 1 AND `lastposteruid` != ". $uid . $tids . $forum_select);
$count_replies = $db->num_rows($query);
// get active & closed total
$query = $db->simple_select("threads", "tid", "visible = 1 AND `closed` = 1". $tids . $forum_select);
$count_closed = $db->num_rows($query);
$count_active = $count_total - $count_closed;
// final query
$threadfield_cache = xthreads_gettfcache();
$xt_fields = '';
if(!empty($threadfield_cache))
{
$fids = array_flip(array_map('intval', explode(',', $fids)));
$all_fids = empty($fids);
$xt_fields = '';
foreach($threadfield_cache as $k => &$v) {
$available = (!$v['forums']) || $all_fids;
if(!$available)
foreach(explode(',', $v['forums']) as $fid) {
if(isset($fids[$fid])) {
$available = true;
break;
}
}
if($available)
$xt_fields .= ', tfd.`'.$v['field'].'` AS `xthreads_'.$v['field'].'`';
}
}
$query = $db->simple_select("threads t LEFT JOIN {$db->table_prefix}threadfields_data tfd ON (tfd.tid=t.tid) LEFT JOIN {$db->table_prefix}users lu ON (lu.uid=t.lastposteruid)", "t.*{$xt_fields},lu.uid AS lastposter_uid,lu.usergroup AS lastposter_usergroup,lu.displaygroup AS lastposter_displaygroup", "t.visible=1". str_replace('tid', 't.tid', $tids) . str_replace('fid', 't.fid', $forum_select ) , array('limit' => $per_page, 'limit_start' => $start, 'order_by' => 't.tid', 'order_dir' => 'desc'));
$xt_tids = '';
!$threadfield_cache || $xt_tids = '0,'.$topics;
if($db->num_rows($query) < 1)
{
eval("\$threadlog_list .= \"". $templates->get("threadlog_nothreads") ."\";");
}
else
{
$table_exists = $db->table_exists('usernotes');
$query4 = $db->simple_select("posts p LEFT JOIN {$db->table_prefix}users u ON (u.uid=p.uid)", "DISTINCT p.uid, p.tid, u.uid, u.username, u.usergroup, u.displaygroup", "p.uid!={$uid}".str_replace('tid', 'p.tid', $tids), ['group_by' => 'p.pid']);
$participants_cache = [];
while($participant = $db->fetch_array($query4)) {
$participants_cache[$participant['tid']][$participant['uid']] = $participant;
}
}
while($thread = $db->fetch_array($query))
{
$page_total++;
$threadfields = array();
if(!empty($threadfield_cache)) {
xthreads_set_threadforum_urlvars('thread', $thread['tid']);
xthreads_set_threadforum_urlvars('forum', $thread['fid']);
foreach($threadfield_cache as $k => &$v) {
if($v['forums'] && strpos(','.$v['forums'].',', ','.$thread['fid'].',') === false)
continue;
xthreads_get_xta_cache($v, $xt_tids);
$threadfields[$k] =& $thread['xthreads_'.$k];
xthreads_sanitize_disp($threadfields[$k], $v, ($thread['username'] !== '' ? $thread['username'] : $thread['threadusername']));
}
}
$tid = $thread['tid'];
$posts_query = $db->simple_select("posts", "tid", "visible = 1 AND tid = '". $tid ."'");
$thread_posts = $db->num_rows($posts_query);
// set up row styles
if($page_total % 2)
{
$thread_row = "trow2";
}
else
{
$thread_row = "trow1";
}
// set up classes for active, needs reply, and closed threads
if($thread['closed'] == 1)
{
$thread_status = "closed";
}
else
{
$thread_status = "active";
// print($thread['lastposteruid']); print $uid; die();
if($thread['lastposteruid'] != $uid)
{
$thread_status .= " needs-reply";
}
}
// set up thread link
$thread_title = "<a href=\"{$mybb->settings['bburl']}/showthread.php?tid=". $thread['tid'] ."\">". $thread['subject'] ."</a>";
// set up thread date
$thread_date = date($mybb->settings['dateformat'], $thread['dateline']);
// set up last poster
$thread_latest_poster = htmlspecialchars_uni($thread['lastposter']);
if($thread['lastposter_uid'])
{
$thread_latest_poster = build_profile_link(format_name($thread_latest_poster, $thread['lastposter_usergroup'], $thread['lastposter_displaygroup']), $thread['lastposter_uid']);
}
// set up date of last post
$thread_latest_date = date($mybb->settings['dateformat'], $thread['lastpost']);
// set up thread prefix
$thread_prefix = '';
$query2 = $db->simple_select("threadprefixes", "displaystyle", "pid = ".$thread['prefix']);
$prefix = $db->fetch_array($query2);
if($thread['prefix'] != 0)
{
$thread_prefix = $prefix['displaystyle'];
}
// set up skills/attributes, but only if it exists!
if($table_exists) {
$usernotes = '';
$query5 = $db->simple_select("usernotes", "*", "tid = ". $thread['tid'] ." AND uid = ".$uid);
$usernotes = $db->fetch_array($query5);
}
// set up participants
$thread_participants = 'N/A';
$i = 0;
if(!empty($participants_cache[$thread['tid']]))
{
$thread_participants = $comma = '';
foreach($participants_cache[$thread['tid']] as $participant) {
$i++;
$username = htmlspecialchars_uni($participant['username']);
$username = format_name($username, $participant['usergroup'], $participant['displaygroup']);
$username = build_profile_link($username, $participant['uid']);
$thread_participants .= $comma.$username;
$comma = $lang->comma;
}
}
// add the row to the list
eval("\$threadlog_list .= \"".$templates->get("threadlog_row")."\";");
} // end while
eval("\$threadlog_page = \"".$templates->get("threadlog_page")."\";");
output_page($threadlog_page);
exit;
} // end threadlog action
}
// add field to ACP
$plugins->add_hook("admin_forum_management_edit", "threadlog_forum_edit");
$plugins->add_hook("admin_forum_management_edit_commit", "threadlog_forum_commit");
function threadlog_forum_edit()
{
global $plugins;
$plugins->add_hook("admin_formcontainer_end", "threadlog_formcontainer_editform");
}
function threadlog_formcontainer_editform()
{
global $mybb, $db, $lang, $form, $form_container, $fid;
// print_r($mybb->input['threadlog_include']); die();
$query = $db->simple_select('forums', 'threadlog_include', "fid='{$fid}'", array('limit' => 1));
$include = $db->fetch_field($query, 'threadlog_include');
if($form_container->_title == "Edit Forum")
{
// create input fields
$threadlog_forum_include = array(
$form->generate_check_box("threadlog_include", 1, "Include in threadlog?", array("checked" => $include))
);
$form_container->output_row("Threadlog", "", "<div class=\"group_settings_bit\">".implode("</div><div class=\"group_settings_bit\">", $threadlog_forum_include)."</div>");
}
}
function threadlog_forum_commit()
{
global $db, $mybb, $cache, $fid;
$update_array = array(
"threadlog_include" => $mybb->get_input('threadlog_include', MyBB::INPUT_INT),
);
$db->update_query("forums", $update_array, "fid='{$fid}'");
$cache->update_forums();
}