============================================================================================================================
Modification Name: Forum Based Mark Threads

Version: 3.0

Author: GuldantheWarlock (GuldantheWarlock@xmbgarage.com)

Last Updated: December 22, 2010

Description:
This modification will allow forum moderators to mark threads (eg: [In Progress], [Resolved]).
The thread prefixes can be set via Admin Panel -> Forums -> More Options.
There are two prefix input boxes. One for open threads and one for closed threads.
There is also an on/off control via the Admin Panel -> Forums -> More Options.
Colors may now be used via the [color] bbcode tag:
    Example: [color=#00FF00]New[/color]

Supported Version: XMB 1.9.5 SP1

Notes: License Note: This modification is released under the GPL License v3. A copy is provided with this software package.

Please backup your files before installing this modification.
Neither XMB Garage nor the author can be held responsible if your board stops functioning properly due to you installing this modification.
============================================================================================================================
=======
Step 1:
=======
====================================
Go To Administration Panel --> Insert Raw SQL
====================================
===================================
Paste The Following Code and Submit Changes:
===================================

ALTER TABLE `$table_forums` ADD `mt_status` SET('on','off') NOT NULL default 'on';
ALTER TABLE `$table_forums` ADD `mt_open` TEXT NOT NULL;
ALTER TABLE `$table_forums` ADD `mt_close` TEXT NOT NULL;
ALTER TABLE `$table_forums` ADD `mt_auto_status` SET('on','off') NOT NULL default 'on';
ALTER TABLE `$table_forums` ADD `mt_auto_prefix` VARCHAR(50) NOT NULL default '';

UPDATE `$table_forums` SET `mt_open`='In Progress, Pending';
UPDATE `$table_forums` SET `mt_close`='Resolved';

============================================================================================================================
=======
Step 2:
=======
==============
Edit File: cp.php
==============
==========
Find Code:
==========

        $type31 = $type32 = $type33 = $type34 = '';
        if ($forum['private'] == 2) {
            $type32 = $selHTML;
        } elseif ($forum['private'] == 3) {
            $type33 = $selHTML;
        } elseif ($forum['private'] == 4) {
            $type34 = $selHTML;
        } elseif ($forum['private'] == 1) {
            $type31 = $selHTML;
        }

===============
Add Code Below:
===============

        // Forum Based Mark Threads Mod Begin
        $markthreads_on = $markthreads_off = '';
        switch ($forum['mt_status']) {
            case 'on':
                $markthreads_on = $selHTML;
                break;
            default:
                $markthreads_off = $selHTML;
                break;
        }

        $mt_auto_on = $mt_auto_off = '';
        switch($forum['mt_auto_status']) {
            case 'on':
                $mt_auto_on = $selHTML;
                break;

            default:
                $mt_auto_off = $selHTML;
                break;
        }
        // Forum Based Mark Threads Mod End

==========
Find Code:
==========

        <tr class="tablerow">
        <td bgcolor="<?php echo $altbg1?>"><?php echo $lang['texttheme']?></td>
        <td bgcolor="<?php echo $altbg2?>"><?php echo $themelist?></td>
        </tr>

===============
Add Code Below:
===============

        <!-- Forum Based Mark Threads Mod Begin -->
        <?php
        printsetting1($lang['markthreadstatus'], 'mt_statusnew', $markthreads_on, $markthreads_off);
        ?>
        <tr class="tablerow">
        <td bgcolor="<?php echo $altbg1?>"><?php echo $lang['markthreadopen']?></td>
        <td bgcolor="<?php echo $altbg2?>"><textarea rows="4" cols="30" name="mt_opennew"><?php echo $forum['mt_open']?></textarea></td>
        </tr>
        <tr class="tablerow">
        <td bgcolor="<?php echo $altbg1?>"><?php echo $lang['markthreadclose']?></td>
        <td bgcolor="<?php echo $altbg2?>"><textarea rows="4" cols="30" name="mt_closenew"><?php echo $forum['mt_close']?></textarea></td>
        </tr>
        <?php
        printsetting1($lang['markthreadautostatus'], 'mt_auto_statusnew', $mt_auto_on, $mt_auto_off);

        $open_prefixes = array_map('trim', explode(',', $forum['mt_open']));
        $auto_prefix = array();
        $auto_prefix[] = '<select name="mt_auto_prefixnew">';
        $auto_prefix[] = '<option value=""'.(($forum['mt_auto_prefix'] == '') ? ' $selHTML' : '').'>'.$lang['textnone'].'</option>';
        foreach($open_prefixes as $prefix) {
            $matches = array();
            $color = (preg_match("#\[color=([^\"'<>]*?)\](.*?)\[/color\]#Ssi", $prefix, $matches)) ? ' style="color: '.$matches[1].';"' : '';
            $auto_prefix[] = '<option value="'.$prefix.'"'.$color.(($forum['mt_auto_prefix'] == $prefix) ? ' selected="selected"' : '').'>'.preg_replace("#\[color=([^\"'<>]*?)\](.*?)\[/color\]#Ssi", '$2', $prefix).'</option>';
        }
        $auto_prefix[] = '</select>';
        $auto_prefix   = implode("\n", $auto_prefix);
        ?>
        <tr class="tablerow">
        <td bgcolor="<?php echo $altbg1?>"><?php echo $lang['markthreadautoprefix']?></td>
        <td bgcolor="<?php echo $altbg2?>"><?php echo $auto_prefix?></td>
        </tr>
        <!-- Forum Based Mark Threads Mod End -->

==========
Find Code:
==========

            if ($newfname != $lang['textnewforum']) {
                $newfname = addslashes($newfname);
                $db->query("INSERT INTO $table_forums ( type, fid, name, status, lastpost, moderator, displayorder, private, description, allowhtml, allowsmilies, allowbbcode, userlist, theme, posts, threads, fup, postperm, allowimgcode, attachstatus, pollstatus, password, guestposting ) VALUES ('forum', '', '$newfname', '$newfstatus', '', '', '$newforder', '1', '', 'no', 'yes', 'yes', '', '', '0', '0', '$newffup', '1|1', 'yes', 'on', 'on', '', 'off')");
            }

===============
Find Code In Line:
===============

) VALUES ('forum',

================
Replace Code With:
================

, mt_status, mt_open, mt_close, mt_auto_status, mt_auto_prefix) VALUES ('forum',

===============================
Find Code At The End Of The Same Line:
===============================

)");

================
Replace Code With:
================

, 'off', '', '', 'off', '')");

==========
Find Code:
==========

            if ($newgname != $lang['textnewgroup']) {
                $newgname = addslashes($newgname);
                $db->query("INSERT INTO $table_forums ( type, fid, name, status, lastpost, moderator, displayorder, private, description, allowhtml, allowsmilies, allowbbcode, userlist, theme, posts, threads, fup, postperm, allowimgcode, attachstatus, pollstatus, password, guestposting ) VALUES ('group', '', '$newgname', '$newgstatus', '', '', '$newgorder', '', '', '', '', '', '', '', '0', '0', '', '', '', '', '', '', 'off')");
            }

===============
Find Code In Line:
===============

) VALUES ('group',

================
Replace Code With:
================

, mt_status, mt_open, mt_close, mt_auto_status, mt_auto_prefix) VALUES ('group',

===============================
Find Code At The End Of The Same Line:
===============================

)");

================
Replace Code With:
================

, 'off', '', '', 'off', '')");

==========
Find Code:
==========

            if ($newsubname != $lang['textnewsubf']) {
                $newsubname = addslashes($newsubname);
                $db->query("INSERT INTO $table_forums ( type, fid, name, status, lastpost, moderator, displayorder, private, description, allowhtml, allowsmilies, allowbbcode, userlist, theme, posts, threads, fup, postperm, allowimgcode, attachstatus, pollstatus, password, guestposting ) VALUES ('sub', '', '$newsubname', '$newsubstatus', '', '', '$newsuborder', '1', '', 'no', 'yes', 'yes', '', '', '0', '0', '$newsubfup', '1|1', 'yes', 'on', 'on', '', 'off')");
            }

===============
Find Code In Line:
===============

) VALUES ('sub',

================
Replace Code With:
================

, mt_status, mt_open, mt_close, mt_auto_status, mt_auto_prefix) VALUES ('sub',

===============================
Find Code At The End Of The Same Line:
===============================

)");

================
Replace Code With:
================

, 'off', '', '', 'off', '')");

==========
Find Code:
==========

            $guestpostingnew = (isset($guestpostingnew) && $guestpostingnew == 'on') ? 'on' : 'off';

===============
Add Code Below:
===============

            // Forum Based Mark Threads Mod Begin
            $mt_statusnew = (isset($mt_statusnew) && $mt_statusnew == 'on') ? 'on' : 'off';
            $mt_auto_statusnew = (isset($mt_auto_statusnew) && $mt_auto_statusnew == 'on') ? 'on' : 'off';
            // Forum Based Mark Threads Mod End

==========
Find Code:
==========

            $descnew = addslashes($descnew);

===============
Add Code Below:
===============

            // Forum Based Mark Threads Mod Begin
            $mt_opennew = addslashes($mt_opennew);
            $mt_closenew = addslashes($mt_closenew);
            $mt_auto_prefixnew = addslashes($mt_auto_prefixnew);
            // Forum Based Mark Threads Mod End

==========
Find Code:
==========

$db->query("UPDATE $table_forums SET name='$namenew',

===============================
Find Code At The End Of The Same Line:
===============================

 WHERE fid='$fdetails'");

================
Replace Code With:
================

, mt_status='$mt_statusnew', mt_open='$mt_opennew', mt_close='$mt_closenew', mt_auto_status='$mt_auto_statusnew', mt_auto_prefix='$mt_auto_prefixnew' WHERE fid='$fdetails'");

============================================================================================================================
=======
Step 3:
=======
===================
Edit File: viewthread.php
===================
==========
Find Code:
==========

    $modoptions = '';
    if ('Moderator' == $status1) {
        eval('$modoptions = "'.template('viewthread_modoptions').'";');
    }

================
Replace Code With:
================

    $modoptions = '';
    if ('Moderator' == $status1) {
        // Forum Based Mark Threads Mod Begin
        $mt_option = '';
        if (isset($forum['mt_status']) && $forum['mt_status'] == 'on') {
            $mt_option = '<option value="markthread">'.$lang['markthread'].'</option>';
        }
        // Forum Based Mark Threads Mod End
        eval('$modoptions = "'.template('viewthread_modoptions').'";');
    }

============================================================================================================================
=======
Step 4:
=======
=====================
Edit File: topicadmin.php
=====================
==========
Find Code:
==========

loadtemplates(

================
Replace Code With:
================

loadtemplates(
'topicadmin_markthread',

==========
Find Code:
==========

    $threadname = stripslashes($thread['subject']);

================
Replace Code With:
================

    $threadname = checkOutput(stripslashes($thread['subject']), 'no', '', true);

==========
Find Code:
==========

    case 'votepoll':
        nav($lang['textvote']);
        break;

===============
Add Code Below:
===============

    // Forum Based Mark Threads Mod Begin
    case 'markthread':
        nav($lang['markthread']);
        if (isset($forums['mt_status']) && $forums['mt_status'] != 'on') {
            $kill = true;
        }
        break;
    // Forum Based Mark Threads Mod End

==========
Find Code:
==========

}

end_time();
eval('echo "'.template('footer').'";');
?>

===============
Add Code Above:
===============

    // Forum Based Mark Threads Mod Begin
    case 'markthread':
        if (!isset($markthreadsubmit) && empty($markthreadsubmit)) {
            // Load Prefixes
            $openprefixes = explode(',', $forums['mt_open']);
            for ($i = 0; $i <count($openprefixes); $i++) {
                $openprefixes[$i] = trim($openprefixes[$i]);
            }

            $closeprefixes = explode(',', $forums['mt_close']);
            for ($i = 0; $i <count($closeprefixes); $i++) {
                $closeprefixes[$i] = trim($closeprefixes[$i]);
            }

            $prefixes = array_merge($openprefixes, $closeprefixes);
            natcasesort($prefixes);

            $colorpattern = "#\[color=([^\"'<>]*?)\](.*?)\[/color\]#Ssi";

            $markthread_select = array();
            $markthread_select[] = '<select name="newmarkthread">';
            $markthread_select[] = '<option value="none">'.$lang['textnone'].'</option>';
            foreach ($prefixes as $prefix) {
                $prefix  = trim($prefix);
                if ($forums['mt_auto_prefix'] == $prefix) {
                    continue;
                }
                $matches = array();
                $color = (preg_match($colorpattern, $prefix, $matches)) ? ' style="color: '.$matches[1].';"' : '';
                $dprefix = preg_replace($colorpattern, '$2', $prefix);
                if (strpos($thread['subject'], '['.$prefix.']') !== false) {
                    $markthread_select[] = '<option value="'.$prefix.'" selected="selected">'.$dprefix.'</option>';
                } else {
                    $markthread_select[] = '<option value="'.$prefix.'">'.$dprefix.'</option>';
                }
            }
            $markthread_select[] = '</select>';
            $markthread_select = implode("\n", $markthread_select);

            eval('echo stripslashes("'.template('topicadmin_markthread').'");');
        } else {
            $mod->statuscheck($fid);

            $query = $db->query("SELECT p.*, t.tid FROM $table_posts p LEFT JOIN $table_threads t ON p.tid=t.tid WHERE p.tid='$tid' ORDER BY dateline LIMIT 0, 1");
            $post = $db->fetch_array($query);
            $db->free_result($query);

            $openprefixes = explode(',', $forums['mt_open']);
            for ($i = 0; $i <count($openprefixes); $i++) {
                $openprefixes[$i] = trim($openprefixes[$i]);
            }

            $closeprefixes = explode(',', $forums['mt_close']);
            for ($i = 0; $i <count($closeprefixes); $i++) {
                $closeprefixes[$i] = trim($closeprefixes[$i]);
            }

            $prefixes = array_merge($openprefixes, $closeprefixes);
            natcasesort($prefixes);

            foreach ($prefixes as $prefix) {
                $prefix = trim($prefix);
                $post['subject'] = str_replace('['.$prefix.']', '', $post['subject']);
            }

            if (in_array($newmarkthread, $closeprefixes) !== false) {
                $closed = 'yes';
            } else {
                $closed = '';
            }

            if ($newmarkthread == 'none') {
                $newmarkthread = '';
            } else {
                $newmarkthread = '['.$newmarkthread.']';
            }

            $subject = addslashes($post['subject']);
            $db->query("UPDATE $table_posts SET subject='$newmarkthread $subject' WHERE pid='$post[pid]'");
            $db->query("UPDATE $table_threads SET closed='$closed', subject='$newmarkthread $subject' WHERE tid='$tid'");

            $mod->log($xmbuser, $action, $fid, $tid);
            eval($lang['markthreadeval']);
            echo '<div align="center"><span class="mediumtxt">'.preg_replace("#\[color=([^\"'<>]*?)\](.*?)\[/color\]#Ssi", '<span style="color: $1;">$2</span>', $lang['markthreadsuccess']).'</span></div>';
            redirect('viewthread.php?tid='.$tid, 2, X_REDIRECT_JS);
        }
        break;
        // Forum Based Mark Threads Mod End

============================================================================================================================
=======
Step 5:
=======
==================
Edit File: functions.php
==================
==========
Find Code:
==========

function checkOutput($output, $allowhtml='no', $word='', $allowEntities=false) {
    $output = trim($output);

===============
Add Code Below:
===============

    // Forum Based Mark Threads Mod Begin
    $output = preg_replace("#\[color=([^\"'<>]*?)\](.*?)\[/color\]#Ssi", '<span style="color: $1;">$2</span>', $output);
    // Forum Based Mark Threads Mod End

============================================================================================================================
=======
Step 6:
=======
=================
Edit File: member.php
=================
==========
Find Code:
==========

                $post['subject'] = censor($post['subject']);

================
Replace Code With:
===============

                $post['subject'] = censor(checkOutput($post['subject'], 'no', '', true));

============================================================================================================================
=======
Step 7:
=======
===============
Edit File: stats.php
===============
==========
Find Code:
==========

    $views_subject = stripslashes(censor($views['subject']));

================
Replace Code With:
================

    $views_subject = checkOutput(stripslashes(censor($views['subject'])), 'on', '', true);

==========
Find Code:
==========

    $reply_subject = stripslashes(censor($reply['subject']));

================
Replace Code With:
================

    $reply_subject = checkOutput(stripslashes(censor($reply['subject'])), 'no', '', true);

==========
Find Code:
==========

    $last_subject = stripslashes(censor($last['subject']));

================
Replace Code With:
================

    $last_subject = checkOutput(stripslashes(censor($last['subject'])), 'no', '', true);

============================================================================================================================
=======
Step 8:
=======
===============
Edit File: post.php
===============
========================
Find Code (First Instance Only):
========================

        $subject = addslashes($subject);

================
Replace Code With:
================

        $subject = addslashes($subject);
        // Forum Based Mark Threads Mod Begin
        if ($forum['mt_auto_status'] == 'on' && $forum['mt_auto_prefix'] != '') {
            $subject = '['.$forum['mt_auto_prefix'].'] '.$subject;
        }
        // Forum Based Mark Threads Mod End

============================================================================================================================
=======
Step 9:
=======
================
Edit File: header.php
================
==========
Find Code:
==========

    $threadSubject = '- '.stripslashes($locate['subject']);

================
Replace Code With:
================

    $threadSubject = '- '.preg_replace('/\[color=(.*)\](.*?)\[\/color\]/', '\2', strip_tags(stripslashes($locate['subject'])));

============================================================================================================================
========
Step 10:
========
=======================
Edit File: lang/English.lang.php
=======================
========================
Add To End Of File Above  ?>
========================

// Forum Based Mark Threads Mod Begin
$lang['markthreadstatus'] = "Mark Thread Status:";
$lang['markthreadopen'] = "Mark Thread Open Prefixes (Separate with comma):<br /><span style=\"font-size: 10px;\">To use a color, specify like so: <em>[color=#FFFFFF]This prefix is white[/color]</em></span>";
$lang['markthreadclose'] = "Mark Thread Closed Prefixes (Separate with comma):<br /><span style=\"font-size: 10px;\">To use a color, specify like so: <em>[color=#FFFFFF]This prefix is white[/color]</em></span>";
$lang['markthread'] = "Mark Thread";
$lang['markthreadmsg'] = "Mark Thread:";
$lang['markthreadeval'] = '$lang["markthreadsuccess"] = "This thread has been marked <strong>$newmarkthread</strong> sucessfully. You will now be taken back to the thread.";'; 
$lang['markthreadautostatus'] = 'Automatically mark new threads with default prefix in this forum?';
$lang['markthreadautoprefix'] = 'Default Prefix:';
// Forum Based Mark Threads Mod End

============================================================================================================================
========
Step 11:
========
===============================
Go To Administration Panel --> Templates
===============================
=============================
Edit Template: viewthread_modoptions
=============================
==========
Find Code:
==========

<option value="" selected></option>

===============
Add Code Below:
===============

$mt_option

============================================================================================================================
========
Step 12:
========
===============================
Go To Administration Panel --> Templates
===============================
==================================
Create New Template: topicadmin_markthread
==================================
========================
Add Code and Submit Changes:
========================

<form method="post" action="topicadmin.php?action=markthread">
<table cellspacing="0" cellpadding="0" border="0" width="$tablewidth" align="center">
<tr>
<td bgcolor="$bordercolor">
<table border="0" cellspacing="$borderwidth" cellpadding="$tablespace" width="100%">
<tr class ="category">
<td colspan="2"><font color="$cattext"><strong>$lang[markthread]</strong></font></td>
</tr>
<tr class="tablerow">
<td bgcolor="$altbg1" width="22%">$lang[loggedinuser]</td>
<td bgcolor="$altbg2" >$xmbuser $lang[textminilogout]</td>
</tr>
<tr class="tablerow">
<td bgcolor="$altbg1" width="14%">$lang[markthreadmsg]</td>
<td bgcolor="$altbg2">$markthread_select</td>
</tr>
<tr class="ctrtablerow" bgcolor="$altbg2">
<td colspan="2">
<input type="hidden" name="fid" value="$fid" />
<input type="hidden" name="tid" value="$tid" />
<input type="submit" class="submit" name="markthreadsubmit" value="$lang[markthread]" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>

============================================================================================================================
Enjoy!