function xthreads_install() { global $db, $cache, $plugins; $plugins->run_hooks('xthreads_install_start'); $create_table_suffix = $db->build_create_table_collation(); $dbtype = xthreads_db_type(); switch ($dbtype) { case 'mysql': $engine = 'MyISAM'; // try to see if a custom table engine is being used $query = $db->query('SHOW TABLE STATUS LIKE "' . $db->table_prefix . 'threads"', true); if ($query) { $eng = $db->fetch_field($query, 'Engine'); if (in_array(strtolower($eng), array('innodb', 'aria', 'xtradb'))) { // only stick to common possibilities to avoid issues with exquisite setups $engine = $eng; } } $create_table_suffix = ' ENGINE=' . $engine . $create_table_suffix; $auto_increment = ' auto_increment'; break; case 'sqlite': $auto_increment = ' PRIMARY KEY'; break; case 'pgsql': $auto_increment = ''; } if ($dbtype != 'mysql') { die('XThreads currently does not support database systems other than MySQL/i.'); } if (!$db->table_exists('threadfields_data')) { $db->write_query('CREATE TABLE ' . $db->table_prefix . 'threadfields_data ( tid ' . xthreads_db_fielddef('int') . ' not null ' . ($dbtype != 'sqlite' ? ', PRIMARY KEY (tid)' : '') . ' )' . $create_table_suffix); } if (!$db->table_exists('xtattachments')) { $db->write_query('CREATE TABLE ' . $db->table_prefix . 'xtattachments ( aid ' . xthreads_db_fielddef('int') . ' not null' . $auto_increment . ', downloads ' . xthreads_db_fielddef('bigint') . ' not null default 0, tid ' . xthreads_db_fielddef('int') . ' not null, uid ' . xthreads_db_fielddef('int') . ' not null default 0, field varchar(50) not null default \'\', posthash varchar(50) not null default \'\', filename varchar(255) not null default \'\', uploadmime varchar(120) not null default \'\', filesize ' . xthreads_db_fielddef('bigint') . ' not null default 0, attachname varchar(120) not null default \'\', indir varchar(40) not null default \'\', md5hash ' . xthreads_db_fielddef('binary', 16) . ' default null, uploadtime ' . xthreads_db_fielddef('bigint') . ' not null default 0, updatetime ' . xthreads_db_fielddef('bigint') . ' not null default 0, thumbs text not null ' . ($dbtype != 'sqlite' ? ', PRIMARY KEY (aid) ' . ($dbtype != 'pg' ? ', KEY (tid), KEY (tid,uid), KEY (posthash), KEY (field) ' : '') . ' ' : '') . ' )' . $create_table_suffix); } if (!$db->table_exists('threadfields')) { $fieldprops = xthreads_threadfields_props(); $query = ''; foreach ($fieldprops as $field => &$prop) { $query .= ($query ? ',' : '') . '`' . $field . '` ' . xthreads_db_fielddef($prop['db_type'], $prop['db_size'], $prop['db_unsigned']) . ' not null'; if (isset($prop['default']) && $prop['db_type'] != 'text') { if ($prop['datatype'] == 'string') { $query .= ' default \'' . $db->escape_string($prop['default']) . '\''; } elseif ($prop['datatype'] == 'double') { $query .= ' default ' . (double) $prop['default']; } else { $query .= ' default ' . (int) $prop['default']; } } if ($field == 'field' && $dbtype == 'sqlite') { $query .= ' PRIMARY KEY'; } } $db->write_query('CREATE TABLE ' . $db->table_prefix . 'threadfields ( ' . $query . ' ' . ($dbtype != 'sqlite' ? ', PRIMARY KEY (field) ' . ($dbtype != 'pg' ? ', KEY (disporder) ' : '') . ' ' : '') . ' )' . $create_table_suffix); // `allowsort` '.xthreads_db_numdef('tinyint').' not null default 0, } foreach (array('grouping' => xthreads_db_fielddef('int') . ' not null default 0', 'firstpostattop' => xthreads_db_fielddef('tinyint') . ' not null default 0', 'inlinesearch' => xthreads_db_fielddef('tinyint') . ' not null default 0', 'tplprefix' => 'text not null', 'langprefix' => 'text not null', 'allow_blankmsg' => xthreads_db_fielddef('tinyint') . ' not null default 0', 'nostatcount' => xthreads_db_fielddef('tinyint') . ' not null default 0', 'fdcolspan_offset' => xthreads_db_fielddef('smallint', null, false) . ' not null default 0', 'settingoverrides' => 'text not null', 'postsperpage' => xthreads_db_fielddef('smallint') . ' not null default 0', 'hideforum' => xthreads_db_fielddef('tinyint') . ' not null default 0', 'hidebreadcrumb' => xthreads_db_fielddef('tinyint') . ' not null default 0', 'defaultfilter' => 'text not null', 'wol_announcements' => 'varchar(255) not null default \'\'', 'wol_forumdisplay' => 'varchar(255) not null default \'\'', 'wol_newthread' => 'varchar(255) not null default \'\'', 'wol_attachment' => 'varchar(255) not null default \'\'', 'wol_newreply' => 'varchar(255) not null default \'\'', 'wol_showthread' => 'varchar(255) not null default \'\'') as $field => $fdef) { if (!$db->field_exists($field, 'forums')) { $db->write_query('ALTER TABLE ' . $db->table_prefix . 'forums ADD COLUMN xthreads_' . $field . ' ' . $fdef); } } // add indexes 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` ADD KEY `xthreads_' . $afe . '` (`' . $afe . '`)', true); } // increase size of sorting column $db->write_query('ALTER TABLE `' . $db->table_prefix . 'forums` MODIFY `defaultsortby` varchar(255) NOT NULL default \'\''); $cache->update_forums(); // check for xthreads_attachment.php supported URL type if (file_exists(MYBB_ROOT . 'xthreads_attach.php')) { // if not, our admin is a dufus $rand = 'aA0._|' . mt_rand(); $rand_md5 = md5($rand); $baseurl = $GLOBALS['mybb']->settings['bburl'] . '/xthreads_attach.php'; if (fetch_remote_file($baseurl . '/test/' . $rand) == $rand_md5) { define('XTHREADS_ATTACH_USE_QUERY', -1); } elseif (fetch_remote_file($baseurl . '?file=test/' . $rand) == $rand_md5) { define('XTHREADS_ATTACH_USE_QUERY', 1); } elseif (fetch_remote_file($baseurl . '?file=test|' . $rand) == $rand_md5) { define('XTHREADS_ATTACH_USE_QUERY', 2); } // else, well, sucks for the user... } xthreads_buildtfcache(); xthreads_write_xtcachefile(); xthreads_insert_templates(xthreads_new_templates(), -2); xthreads_plugins_quickthread_tplmod(); // admin permissions - default to all allow $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 $perms['config']['threadfields'] = 1; $db->update_query('adminoptions', array('permissions' => $db->escape_string(serialize($perms))), 'uid=' . $adminopt['uid']); } $db->free_result($query); $plugins->run_hooks('xthreads_install_end'); }
function xthreads_vercheck() { global $admin_session, $lang, $mybb; $upgrade_link = 'index.php?xthreads_upgrade=1&my_post_key=' . $mybb->post_code; if ($mybb->request_mode != 'post') { if ($qs = $_SERVER['QUERY_STRING']) { $qs = preg_replace('~(^|&)my_post_key=.*?(&|$)~i', '$2', $qs); if ($qs[0] != '&') { $qs = '&' . $qs; } $upgrade_link .= htmlspecialchars($qs); } } // whilst we're here, also check if evalcache file exists if (!file_exists(MYBB_ROOT . 'cache/xthreads_evalcache.php')) { xthreads_buildtfcache(); } if (!defined('XTHREADS_INSTALLED_VERSION')) { // 1.32 or older $info = @(include MYBB_ROOT . 'cache/xthreads.php'); if (is_array($info)) { define('XTHREADS_INSTALLED_VERSION', $info['version']); } else { // can't retrieve info! define('XTHREADS_INSTALLED_VERSION', XTHREADS_VERSION); // fallback // try to rewrite file if possible if (!$lang->xthreads_cachefile_rewritten) { $lang->load('xthreads'); } if ($mybb->input['xthreads_upgrade'] && $mybb->input['my_post_key'] == $mybb->post_code) { xthreads_write_xtcachefile(); $msg = array('message' => $lang->sprintf($lang->xthreads_cachefile_rewritten, XTHREADS_INSTALLED_VERSION), 'type' => 'success'); unset($mybb->input['xthreads_upgrade']); } else { $msg = array('message' => $lang->sprintf($lang->xthreads_cachefile_missing, xthreads_format_version_number(XTHREADS_VERSION), $upgrade_link), 'type' => 'alert'); } } } if (XTHREADS_INSTALLED_VERSION < XTHREADS_VERSION) { // need to upgrade if (!$lang->xthreads_upgrade_done) { $lang->load('xthreads'); } if ($mybb->input['xthreads_upgrade'] && $mybb->input['my_post_key'] == $mybb->post_code) { if (!file_exists(MYBB_ROOT . 'cache/xthreads.php')) { touch(MYBB_ROOT . 'cache/xthreads.php'); } if (is_writable(MYBB_ROOT . 'cache/xthreads.php')) { // perform upgrade $result = (require MYBB_ROOT . 'inc/xthreads/xt_upgrader.php'); if ($result === true) { xthreads_write_xtcachefile(); $msg = array('message' => $lang->xthreads_upgrade_done, 'type' => 'success'); } else { $msg = array('message' => $lang->xthreads_upgrade_failed, 'type' => 'error'); if (is_string($result) && $result) { $msg['message'] .= ' ' . $result; } } } else { $msg = array('message' => $lang->xthreads_upgrade_failed . $lang->xthreads_cachefile_not_writable, 'type' => 'error'); } unset($mybb->input['xthreads_upgrade']); } else { $msg = array('message' => $lang->sprintf($lang->xthreads_do_upgrade, xthreads_format_version_number(XTHREADS_VERSION), xthreads_format_version_number(XTHREADS_INSTALLED_VERSION), $upgrade_link), 'type' => 'alert'); } } if ($msg) { if (isset($admin_session['data']['flash_message'])) { $admin_session['data']['flash_message']['message'] .= '</div><br /><div class="' . $msg['type'] . '">' . $msg['message']; } else { $admin_session['data']['flash_message'] =& $msg; } } }