function xthreads_delete_thread($tid) { global $db; // awesome thing about this is that it will delete threadfields even if the thread was moved to a different forum $db->delete_query('threadfields_data', 'tid=' . $tid); xthreads_rm_attach_query('tid=' . $tid); }
function &upload_xtattachment($attachment, &$tf, $uid, $update_attachment = 0, $tid = 0) { $attacharray = do_upload_xtattachment($attachment, $tf, $update_attachment, $tid); if ($attacharray['error']) { return $attacharray; } // perform user flood checking static $done_flood_check = false; if ($uid && !$done_flood_check && $attacharray['aid']) { require_once MYBB_ROOT . 'inc/xthreads/xt_modupdhooks.php'; $done_flood_check = true; xthreads_rm_attach_query('tid=0 AND uid=' . (int) $uid . ' AND aid != ' . $attacharray['aid'] . ' AND updatetime < ' . (TIME_NOW - XTHREADS_UPLOAD_EXPIRE_TIME)); // we'll do an extra query to get around the issue of delete queries not supporting offsets global $db; $cutoff = $db->fetch_field($db->simple_select('xtattachments', 'uploadtime', 'tid=0 AND uid=' . (int) $uid . ' AND aid != ' . $attacharray['aid'] . ' AND uploadtime > ' . (TIME_NOW - XTHREADS_UPLOAD_FLOOD_TIME), array('order_by' => 'uploadtime', 'order_dir' => 'desc', 'limit' => 1, 'limit_start' => XTHREADS_UPLOAD_FLOOD_NUMBER)), 'uploadtime'); if ($cutoff) { xthreads_rm_attach_query('tid=0 AND uid=' . (int) $uid . ' AND aid != ' . $attacharray['aid'] . ' AND uploadtime > ' . (TIME_NOW - XTHREADS_UPLOAD_FLOOD_TIME) . ' AND uploadtime <= ' . $cutoff); } } return $attacharray; }
function task_xtaorphan_cleanup(&$task) { global $db, $lang, $plugins, $mybb; if (is_object($plugins)) { $plugins->run_hooks('xthreads_task_xtacleanup', $task); } // clean out orphaned xtattachments more than 1 day old require_once MYBB_ROOT . 'inc/xthreads/xt_modupdhooks.php'; $count = xthreads_rm_attach_query('tid=0 AND uploadtime<' . (TIME_NOW - 86400)); // setting "isdatahandler" to true is destructive!!! if (!$lang->task_xtaorphan_run_done) { $lang->load('xthreads', true); } if ($count) { add_task_log($task, $lang->sprintf($lang->task_xtaorphan_run_cleaned, $count)); } else { add_task_log($task, $lang->task_xtaorphan_run_done); } // also perform deferred MD5 hashing $query = $db->simple_select('xtattachments', 'aid,indir,attachname,updatetime', 'md5hash IS NULL'); if (isset($db->db_encoding)) { // hack for MyBB >= 1.6.12 to force it to not screw up our binary field $old_db_encoding = $db->db_encoding; $db->db_encoding = 'binary'; } while ($xta = $db->fetch_array($query)) { $file = xthreads_get_attach_path($xta); $file_md5 = @md5_file($file, true); if (strlen($file_md5) == 32) { // perhaps not PHP5 $file_md5 = pack('H*', $file_md5); } // we ensure that the attachment hasn't been updated during the hashing process by double-checking the updatetime field $db->update_query('xtattachments', array('md5hash' => $db->escape_string($file_md5)), 'aid=' . $xta['aid'] . ' AND updatetime=' . $xta['updatetime']); } if (isset($old_db_encoding)) { $db->db_encoding = $old_db_encoding; } }
WHERE t.tid IS NULL'); /* other queries, which seem to be slower * select tid from mybb_threadfields_data where tid not in (select tid from mybb_threads) * ^ about same speed * select tid from mybb_threadfields_data tfd where not exists (select tid from mybb_threads t where t.tid=tfd.tid) * ^ a fair bit slower */ $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"<>&]*)?$') . '"'); }
function xthreads_admin_userprune_do() { $tids = implode(',', $GLOBALS['prune_array']['to_delete']); if (!$tids) { return; } $qin = 'tid IN (' . $tids . ')'; $GLOBALS['db']->delete_query('threadfields_data', $qin); require_once MYBB_ROOT . 'inc/xthreads/xt_modupdhooks.php'; xthreads_rm_attach_query($qin); }
function xthreads_attach_clear_posthash() { if (mt_rand(0, 10) > 1) { return; } // dirty hack to speed things up a little require_once MYBB_ROOT . 'inc/xthreads/xt_modupdhooks.php'; xthreads_rm_attach_query('posthash="' . $GLOBALS['db']->escape_string($GLOBALS['posthash']) . '"'); }
$order[] = $efn; $db->update_query('threadfields', array('disporder' => $new_order), 'field="' . $efn . '"'); } } } $db->free_result($query); if (!empty($del)) { $plugins->run_hooks('admin_config_threadfields_inline_delete'); $db->delete_query('threadfields', 'field IN ("' . implode('","', $del) . '")'); $db->write_query('ALTER TABLE `' . $db->table_prefix . 'threadfields_data` DROP COLUMN `' . implode('`, DROP COLUMN `', $del) . '`' . $alterkeys); // delete attachments? - might be a little slow... if (!empty($delattach)) { @ignore_user_abort(true); @set_time_limit(0); require_once MYBB_ROOT . 'inc/xthreads/xt_modupdhooks.php'; xthreads_rm_attach_query('field IN ("' . implode('","', $delattach) . '")'); } } $plugins->run_hooks('admin_config_threadfields_inline_end'); if (empty($order) && empty($del)) { // nothing updated flash_message($lang->failed_threadfield_inline, 'error'); admin_redirect(xthreads_admin_url('config', 'threadfields')); } else { // Log admin action log_admin_action(implode(', ', $order), implode(', ', $del)); xthreads_buildtfcache(); flash_message($lang->success_threadfield_inline, 'success'); admin_redirect(xthreads_admin_url('config', 'threadfields')); } }