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'); }
// hideedit -> hidefield transition $db->update_query('threadfields', array('hidefield' => XTHREADS_HIDE_THREAD)); $db->update_query('threadfields', array('hidefield' => XTHREADS_HIDE_INPUT | XTHREADS_HIDE_THREAD), 'hideedit != 0'); $db->write_query('ALTER TABLE `' . $db->table_prefix . 'threadfields` DROP COLUMN `hideedit`'); // fix email masks $db->update_query('threadfields', array('textmask' => $db->escape_string('^([^ "(),:;<>@\\[\\\\\\]]+)@([a-z0-9_.\\-]+)$')), 'textmask="' . $db->escape_string('^([a-z0-9_.\\-]+)@([a-z0-9_.\\-]+)$') . '"'); // we never used this, so may as well get rid of it $db->write_query('ALTER TABLE `' . $db->table_prefix . 'forums` DROP COLUMN `xthreads_wol_xtattachment`'); if (XTHREADS_MODIFY_TEMPLATES) { find_replace_templatesets('showthread', '#\\{\\$classic_header\\}#', '{$threadfields_display}{$classic_header}'); } require_once MYBB_ROOT . 'inc/xthreads/xt_install.php'; // migrate templates - surely no-one else is ending their template names with "threadfields_inputrow", right? $db->write_query('UPDATE `' . $db->table_prefix . 'templates` SET title=CONCAT(SUBSTRING(title, 0, -21), "post_threadfields_inputrow") WHERE title LIKE "%threadfields_inputrow"'); // global -> master template conversion $newtpl = xthreads_new_templates(); // WARNING: if templates change, this could get funky function xtu_normalize_template($s) { return str_replace(' />', '/>', strtr(preg_replace('~\\s+~', ' ', trim($s)), array('> ' => '>', ' <' => '<'))); } $query = $db->simple_select('templates', 'title,template', 'title IN ("editpost_first","forumdisplay_group_sep","forumdisplay_thread_null","showthread_noreplies","forumdisplay_searchforum_inline","post_threadfields_inputrow") AND sid=-1'); $rmtpl = array(); while ($tpl = $db->fetch_array($query)) { if (xtu_normalize_template($tpl['template']) == xtu_normalize_template($newtpl[$tpl['title']])) { // templates seem to be the same, remove $rmtpl[] = $tpl['title']; } } if (!empty($rmtpl)) { $db->delete_query('templates', 'title IN ("' . implode('","', $rmtpl) . '") AND sid=-1');