function xthreads_showthread_firstpost_hack() { if (xthreads_tpl_postbithack()) { // *sigh* no other way to do this other than to hack the templates object again... >_> control_object($GLOBALS['templates'], ' function get($title, $eslashes=1, $htmlcomments=1) { static $done=false; if(!$done && ($title == \'postbit\' || $title == \'postbit_classic\')) { $done = true; $r = parent::get($title, $eslashes, $htmlcomments); xthreads_tpl_postbitrestore(); //return str_replace(\'{$post_extra_style}\', \'border-top-width: 0;\', $r); return \'".($post_extra_style="border-top-width: 0;"?"":"")."\'.$r; } else return parent::get($title, $eslashes, $htmlcomments); } '); } }
function xthreads_inputdisp() { global $thread, $post, $fid, $mybb, $plugins; // work around for editpost bug in MyBB prior to 1.4.12 (http://dev.mybboard.net/issues/374) // this function should only ever be run once static $called = false; if ($called) { return; } $called = true; $editpost = $GLOBALS['current_page'] == 'editpost.php'; if ($editpost) { // because the placement of the editpost_start hook really sucks... if (!$post) { $post = get_post((int) $mybb->input['pid']); // hopefully MyBB will also use get_post in their code too... } if (!$thread) { if (!empty($post)) { $thread = get_thread($post['tid']); } if (empty($thread)) { return; } } if (!$fid) { $fid = $thread['fid']; } // check if first post if ($post['pid'] != $thread['firstpost']) { return; } } if ($mybb->request_method == 'post') { $recvfields = array(); foreach ($mybb->input as $k => &$v) { if (substr($k, 0, 9) == 'xthreads_') { $recvfields[substr($k, 9)] =& $v; } } _xthreads_input_generate($recvfields, $fid, $thread['tid']); } elseif ($editpost || $mybb->input['action'] == 'editdraft' && $thread['tid']) { $blank = array(); _xthreads_input_generate($blank, $fid, $thread['tid']); } else { // newthread.php $blank = array(); _xthreads_input_generate($blank, $fid); // is this really a good idea? it may be possible to delete the current attachments connected to this post! // Update: hmm, perhaps unlikely, since this will only run if a POST request isn't made $plugins->add_hook('newthread_end', 'xthreads_attach_clear_posthash'); } // editpost_first template hack if ($editpost && !xthreads_empty($GLOBALS['templates']->cache['editpost_first'])) { $plugins->add_hook('editpost_end', 'xthreads_editpost_first_tplhack'); } if ($mybb->input['previewpost'] || $editpost) { global $threadfields, $forum; // $forum may not exist for editpost if (empty($forum)) { if (!empty($GLOBALS['thread'])) { // should be set $fid = $GLOBALS['thread']['fid']; } else { // last ditch resort, grab everything from the post $pid = (int) $mybb->input['pid']; $post = get_post($pid); $fid = $post['fid']; } $forum = get_forum($fid); } $threadfields = array(); $threadfield_cache = xthreads_gettfcache($fid); // don't use global cache as that will probably have been cleared of uneditable fields $errors = xthreads_input_validate($threadfields, $threadfield_cache, $editpost ? $thread['tid'] : false); // don't validate here if on editpost, as MyBB will do it later (does a full posthandler validate call) // unfortunately, this method has the side effect of running our validation function twice :( [but not a big issue I guess] if ($editpost || empty($errors)) { // grab threadfields global $db; if (!empty($threadfield_cache)) { if ($thread['tid']) { $curthreaddata = array(); foreach ($threadfield_cache as $k => &$v) { if (!isset($threadfields[$k])) { if (empty($curthreaddata)) { $curthreaddata = $db->fetch_array($db->simple_select('threadfields_data', '`' . implode('`,`', array_keys($threadfield_cache)) . '`', 'tid=' . $thread['tid'])); if (empty($curthreaddata)) { break; } // there isn't anything set for this thread } $threadfields[$k] =& $curthreaddata[$k]; } } $tidstr = $thread['tid']; $posthashstr = ''; $usernamestr = $thread['username']; } else { $tidstr = ''; $posthashstr = $mybb->input['posthash']; $usernamestr = $mybb->user['username']; } foreach ($threadfield_cache as $k => &$v) { xthreads_get_xta_cache($v, $tidstr, $posthashstr); xthreads_sanitize_disp($threadfields[$k], $v, $usernamestr); } } // do first post hack if applicable //if($forum['xthreads_firstpostattop']) { //require_once MYBB_ROOT.'inc/xthreads/xt_sthreadhooks.php'; // above file should already be included if (function_exists('xthreads_tpl_postbithack')) { xthreads_tpl_postbithack(); } //} } else { // block preview if there's errors // <removed previously commented out code which blocked preview by unsetting the previewpost input> // we'll block by forcing an error, so we can get a hook in somewhere... if (!$mybb->input['ajax']) { // will not happen, but be pedantic $GLOBALS['xthreads_backup_subject'] = $mybb->input['subject']; $GLOBALS['xthreads_preview_errors'] =& $errors; $mybb->input['subject'] = ''; control_object($GLOBALS['templates'], ' function get($title, $eslashes=1, $htmlcomments=1) { static $done = false; if(!$done && $title == "error_inline") { $done = true; return str_replace(\'{$errorlist}\', xthreads_blockpreview_hook(), parent::get($title, $eslashes, $htmlcomments)); } return parent::get($title, $eslashes, $htmlcomments); } '); function xthreads_blockpreview_hook() { global $posthandler; $posthandler->data['subject'] = $GLOBALS['mybb']->input['subject'] = $GLOBALS['xthreads_backup_subject']; // remove the error foreach ($posthandler->errors as $k => &$v) { if ($v['error_code'] == 'missing_subject' || $v['error_code'] == 'firstpost_no_subject') { unset($posthandler->errors[$k]); } } // and recheck $posthandler->verify_subject(); xthreads_posthandler_add_errors($posthandler, $GLOBALS['xthreads_preview_errors']); $GLOBALS['lang']->load('xthreads'); $errorlist = ''; foreach ($posthandler->get_friendly_errors() as $error) { $errorlist .= '<li>' . $error . '</li>'; } return $errorlist; } } } // message length hack for newthread if (!$editpost && $forum['xthreads_allow_blankmsg'] && my_strlen($mybb->input['message']) == 0) { $mybb->input['message'] = str_repeat('-', max((int) $mybb->settings['minmessagelength'], 1)); function xthreads_newthread_prev_blankmsg_hack() { static $done = false; if ($done) { return; } $done = true; $GLOBALS['message'] = ''; $GLOBALS['mybb']->input['message'] = ''; } function xthreads_newthread_prev_blankmsg_hack_postbit(&$p) { $p['message'] = ''; xthreads_newthread_prev_blankmsg_hack(); } $plugins->add_hook('newthread_end', 'xthreads_newthread_prev_blankmsg_hack'); $plugins->add_hook('postbit_prev', 'xthreads_newthread_prev_blankmsg_hack_postbit'); } } }