Example #1
0
function xthreads_uninstall()
{
    global $db, $cache, $mybb, $plugins;
    if ($mybb->input['no']) {
        admin_redirect(xthreads_admin_url('config', 'plugins'));
        exit;
    }
    if (!$mybb->input['confirm_uninstall']) {
        $link = 'index.php?confirm_uninstall=1&' . htmlspecialchars($_SERVER['QUERY_STRING']);
        $GLOBALS['page']->output_confirm_action($link, $GLOBALS['lang']->xthreads_confirm_uninstall);
        exit;
    } else {
        unset($mybb->input['confirm_uninstall']);
    }
    $plugins->run_hooks('xthreads_uninstall_start');
    $query = $db->simple_select('adminoptions', 'uid,permissions');
    while ($adminopt = $db->fetch_array($query)) {
        $perms = @unserialize($adminopt['permissions']);
        if (empty($perms)) {
            continue;
        }
        // inherited or just messed up
        unset($perms['config']['threadfields']);
        $db->update_query('adminoptions', array('permissions' => $db->escape_string(serialize($perms))), 'uid=' . $adminopt['uid']);
    }
    $db->free_result($query);
    if ($db->table_exists('threadfields_data')) {
        $db->write_query('DROP TABLE ' . $db->table_prefix . 'threadfields_data');
    }
    if ($db->table_exists('threadfields')) {
        $db->write_query('DROP TABLE ' . $db->table_prefix . 'threadfields');
    }
    if ($db->table_exists('xtattachments')) {
        // remove attachments first
        require_once MYBB_ROOT . 'inc/xthreads/xt_updatehooks.php';
        $query = $db->simple_select('xtattachments', 'aid,indir,attachname');
        while ($xta = $db->fetch_array($query)) {
            xthreads_rm_attach_fs($xta);
        }
        $db->free_result($query);
        $db->write_query('DROP TABLE ' . $db->table_prefix . 'xtattachments');
    }
    // remove any indexes added on the threads table
    foreach (array('uid', 'lastposteruid', 'prefix', 'icon') as $afe) {
        if ($afe == 'uid') {
            continue;
        }
        // we won't remove this from the above array
        $db->write_query('ALTER TABLE `' . $db->table_prefix . 'threads` DROP KEY `xthreads_' . $afe . '`', true);
    }
    $fields = array('xthreads_grouping', 'xthreads_firstpostattop', 'xthreads_inlinesearch', 'xthreads_tplprefix', 'xthreads_langprefix', 'xthreads_allow_blankmsg', 'xthreads_nostatcount', 'xthreads_fdcolspan_offset', 'xthreads_settingoverrides', 'xthreads_postsperpage', 'xthreads_hideforum', 'xthreads_hidebreadcrumb', 'xthreads_defaultfilter', 'xthreads_addfiltenable', 'xthreads_wol_announcements', 'xthreads_wol_forumdisplay', 'xthreads_wol_newthread', 'xthreads_wol_attachment', 'xthreads_wol_newreply', 'xthreads_wol_showthread');
    foreach ($fields as $k => &$f) {
        if (!$db->field_exists($f, 'forums')) {
            unset($fields[$k]);
        }
    }
    if (!empty($fields)) {
        switch ($db->type) {
            case 'sqlite3':
            case 'sqlite2':
            case 'sqlite':
                $db->alter_table_parse($db->table_prefix . 'forums', 'DROP ' . implode(', DROP COLUMN ', $fields) . '');
                break;
            case 'pgsql':
                foreach ($fields as &$f) {
                    $db->write_query('ALTER TABLE ' . $db->table_prefix . 'forums
						DROP COLUMN ' . $f);
                }
                break;
            default:
                $db->write_query('ALTER TABLE ' . $db->table_prefix . 'forums
					DROP COLUMN ' . implode(', DROP COLUMN ', $fields));
        }
    }
    // remove any custom default sorts and reduce size of sorting column back to original
    $db->update_query('forums', array('defaultsortby' => ''), 'defaultsortby LIKE "tf_%" OR defaultsortby LIKE "tfa_%"');
    $db->write_query('ALTER TABLE `' . $db->table_prefix . 'forums` MODIFY `defaultsortby` varchar(10) NOT NULL default \'\'');
    $cache->update_forums();
    xthreads_delete_datacache('threadfields');
    @unlink(MYBB_ROOT . 'cache/xthreads.php');
    @unlink(MYBB_ROOT . 'cache/xthreads_evalcache.php');
    $db->delete_query('templates', 'title IN ("' . implode('","', array_keys(xthreads_new_templates())) . '") AND sid=-2');
    // revert QuickThread modification
    if (function_exists('quickthread_uninstall')) {
        $tpl = $db->fetch_array($db->simple_select('templates', 'tid,template', 'title="forumdisplay_quick_thread" AND sid=-1', array('limit' => 1)));
        if ($tpl && strpos($tpl['template'], '{$GLOBALS[\'extra_threadfields\']}') !== false) {
            $newtpl = preg_replace('~\\{\\$GLOBALS\\[\'extra_threadfields\'\\]\\}' . "\r?(\n\t{0,3})?" . '~is', '', $tpl['template'], 1);
            if ($newtpl != $tpl['template']) {
                $db->update_query('templates', array('template' => $db->escape_string($newtpl)), 'tid=' . $tpl['tid']);
            }
        }
    }
    // try to determine and remove stuff added to the custom moderation table
    $query = $db->simple_select('modtools', 'tid,threadoptions');
    while ($tool = $db->fetch_array($query)) {
        $opts = unserialize($tool['threadoptions']);
        if (isset($opts['edit_threadfields'])) {
            unset($opts['edit_threadfields']);
            $db->update_query('modtools', array('threadoptions' => $db->escape_string(serialize($opts))), 'tid=' . $tool['tid']);
        }
    }
    $plugins->run_hooks('xthreads_uninstall_end');
}
Example #2
0
    $tids = '';
    while ($tid = $db->fetch_field($query, 'tid')) {
        $tids .= ($tids ? ',' : '') . $tid;
    }
    $db->free_result($query);
    if ($tids) {
        $db->delete_query('threadfields_data', 'tid IN (' . $tids . ')');
        require_once MYBB_ROOT . 'inc/xthreads/xt_modupdhooks.php';
        xthreads_rm_attach_query('tid IN (' . $tids . ')');
    }
    require_once MYBB_ROOT . 'inc/xthreads/xt_install.php';
    xthreads_plugins_quickthread_tplmod();
    $xt_forums_cache = $cache->read('xt_forums');
    if (!empty($xt_forums_cache)) {
        // remove old xt_forums cache if present
        xthreads_delete_datacache('xt_forums');
    }
}
if (XTHREADS_INSTALLED_VERSION < 1.45 && XTHREADS_INSTALLED_VERSION > 1.32) {
    // we'll fix up broken regexes in these versions if they exist
    // note that this does assume people haven't deliberately used bad regexes
    $db->update_query('threadfields', array('textmask' => $db->escape_string('^(https?)\\://([a-z0-9.\\-_]+)(/[^\\r\\n"<>&]*)?$')), 'textmask="' . $db->escape_string('^(https?)\\://([a-z.\\-_]+)(/[^\\r\\n"<>&]*)?$') . '"');
    $db->update_query('threadfields', array('textmask' => $db->escape_string('^([a-z0-9]+)\\://([a-z0-9.\\-_]+)(/[^\\r\\n"<>&]*)?$')), 'textmask="' . $db->escape_string('^([a-z0-9]+)\\://([a-z.\\-_]+)(/[^\\r\\n"<>&]*)?$') . '"');
}
if (XTHREADS_INSTALLED_VERSION < 1.5) {
    // template modification
    $tpl_threadfields_inputrow = $db->fetch_field($db->simple_select('templates', 'template', 'title="threadfields_inputrow" AND sid=-1'), 'template');
    if ($tpl_threadfields_inputrow) {
        $newtpl = preg_replace('~^(\\s*\\<tr)\\>~i', '$1 class="xthreads_inputrow">', $tpl_threadfields_inputrow);
        if ($newtpl != $tpl_threadfields_inputrow) {
            $db->update_query('templates', array('template' => $db->escape_string($newtpl)), 'title="threadfields_inputrow" AND sid=-1');