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_tpl_forumbits(&$forum) { static $done = false; global $templates; if (!$done) { $done = true; function xthreads_tpl_forumbits_tplget(&$obj, &$forum, $title, $eslashes, $htmlcomments) { if ($forum['xthreads_hideforum']) { // alternate the bgcolor if applicable (so we get no net change) if ($title == 'forumbit_depth1_cat' || $title == 'forumbit_depth2_cat' || $title == 'forumbit_depth2_forum') { $GLOBALS['bgcolor'] = alt_trow(); } return 'return "";'; } global $forum_tpl_prefixes; if (!empty($forum_tpl_prefixes[$forum['fid']])) { foreach ($forum_tpl_prefixes[$forum['fid']] as &$p) { if (isset($obj->cache[$p . $title]) && !isset($obj->non_existant_templates[$p . $title])) { $title = $p . $title; break; } } } return 'return "' . $obj->xthreads_tpl_forumbits_get($title, $eslashes, $htmlcomments) . '";'; } control_object($templates, ' function get($title, $eslashes=1, $htmlcomments=1) { if(substr($title, 0, 9) != \'forumbit_\') return parent::get($title, $eslashes, $htmlcomments); return \'".eval(xthreads_tpl_forumbits_tplget($templates, $forum, \\\'\'.strtr($title, array(\'\\\\\' => \'\\\\\\\\\', \'\\\'\' => \'\\\\\\\'\')).\'\\\', \'.$eslashes.\', \'.$htmlcomments.\'))."\'; } function xthreads_tpl_forumbits_get($title, $eslashes, $htmlcomments){ return parent::get($title, $eslashes, $htmlcomments); } '); } xthreads_set_threadforum_urlvars('forum', $forum['fid']); }
function ougc_showinportal_portal() { global $db, $settings; control_object($db, ' function query($string, $hide_errors=0, $write_query=0) { if(!$write_query && strpos($string, \'ORDER BY t.dateline DESC\')) { $string = strtr($string, array( \'t.closed\' => \'t.showinportal=\\\'1\\\' AND t.closed\' )); } if(!$write_query && strpos($string, \'OUNT(t.tid) AS thread\')) { $string = strtr($string, array( \'t.visible\' => \'t.showinportal=\\\'1\\\' AND t.visible\' )); } return parent::query($string, $hide_errors, $write_query); } '); // Replace MyCode with a "Read More..." kind of link if (!empty($settings['ougc_showinportal_tag'])) { global $plugins; $plugins->add_hook('portal_announcement', create_function('', 'global $announcement; ougc_showinportal_cutoff($announcement[\'message\'], $announcement[\'fid\'], $announcement[\'tid\']);')); } }
function xthreads_editpost_first_tplhack() { control_object($GLOBALS['templates'], ' function get($title, $eslashes=1, $htmlcomments=1) { static $done=false; if(!$done && $title == "editpost") { $done = true; return parent::get($title, $eslashes, $htmlcomments).\'"; $editpost = "\'.$this->get("editpost_first", $eslashes, $htmlcomments); } return parent::get($title, $eslashes, $htmlcomments); } '); }
function xthreads_info() { global $lang, $mybb, $plugins; $lang->load('xthreads'); $info = array('name' => '<span style="color: #008000;">' . $lang->xthreads_name . '</span>', 'description' => $lang->xthreads_desc, 'website' => 'http://mybbhacks.zingaburga.com/showthread.php?tid=288', 'author' => 'ZiNgA BuRgA', 'authorsite' => 'http://mybbhacks.zingaburga.com/', 'version' => xthreads_format_version_number(XTHREADS_VERSION), 'compatibility' => '14*,15*,16*,17*,18*', 'guid' => ''); if (is_object($plugins)) { $info = $plugins->run_hooks('xthreads_info_needs_moar_pimpin', $info); } if ($mybb->input['action'] || !is_object($GLOBALS['table'])) { // not main plugins page return $info; } if ($mybb->version_code >= 1700) { return $info; } static $done = false; if (!$done) { $done = true; // let's have some fun here control_object($GLOBALS['table'], ' function construct_row($extra = array()) { static $done=false; if(!$done) { xthreads_info_no_more_fun(); $done = true; } return parent::construct_row($extra); } '); $lang->__activate = $lang->activate; $lang->__deactivate = $lang->deactivate; $lang->__install_and_activate = $lang->install_and_activate; $lang->__uninstall = $lang->uninstall; $imgcode = '<![if gte IE 8]><img src="data:image/png;base64,{data}" alt="" style="vertical-align: middle;" /><![endif]> '; $lang->install_and_activate = str_replace('{data}', xthreads_install_img_install(), $imgcode) . '<span style="color: #008000;">' . $lang->xthreads_install_and_activate . '</span>'; $lang->activate = str_replace('{data}', xthreads_install_img_activate(), $imgcode) . '<span style="color: #FF8000;">' . $lang->activate . '</span>'; $lang->deactivate = str_replace('{data}', xthreads_install_img_deactivate(), $imgcode) . '<span style="color: #20A0A0;">' . $lang->deactivate . '</span>'; $lang->uninstall = str_replace('{data}', xthreads_install_img_uninstall(), $imgcode) . '<span style="color: #FF0000;">' . $lang->uninstall . '</span>'; } return array('name' => '</strong><small style="font-family: Tempus Sans ITC, Lucida Calligraphy, Harrington, Comic Sans MS, Some other less-readable goofy font, Serif"><a href="' . $info['website'] . '">' . $info['name'] . '</a> v' . $info['version'] . ', ' . $lang->xthreads_fun_desc . '<!-- ', 'author' => '--><i><small>', 'compatibility' => $info['compatibility'], 'guid' => $info['guid']); }
function xthreads_global() { global $current_page, $mybb, $templatelist, $templates; if ($current_page == 'index.php' || $current_page == 'forumdisplay.php') { global $plugins; require_once MYBB_ROOT . 'inc/xthreads/xt_forumdhooks.php'; $plugins->add_hook('forumdisplay_start', 'xthreads_forumdisplay'); $plugins->add_hook('build_forumbits_forum', 'xthreads_tpl_forumbits'); xthreads_global_forumbits_tpl(); } switch ($current_page) { case 'misc.php': if ($mybb->input['action'] != 'rules') { break; } case 'forumdisplay.php': case 'newthread.php': case 'moderation.php': $fid = (int) $mybb->input['fid']; if ($fid) { break; } case 'polls.php': switch ($mybb->input['action']) { case 'editpoll': case 'do_editpoll': case 'showresults': case 'vote': case 'do_undovote': // no cached poll getting function, dupe a query then... global $db; $tid = $db->fetch_field($db->simple_select('polls', 'tid', 'pid=' . (int) $mybb->input['pid']), 'tid'); } // fall through // fall through case 'showthread.php': case 'newreply.php': case 'ratethread.php': case 'sendthread.php': case 'printthread.php': if (isset($tid) || ($tid = (int) $mybb->input['tid'])) { $thread = get_thread($tid); if ($thread['fid']) { $fid = $thread['fid']; $set_thread_urlvar = $thread['tid']; } } if ($fid || $current_page == 'polls.php') { break; } case 'editpost.php': if ($pid = (int) $mybb->input['pid']) { $post = get_post($pid); if ($post['fid']) { $fid = $post['fid']; $set_thread_urlvar = $post['tid']; } } break; case 'announcements.php': if ($aid = (int) $mybb->input['aid']) { // unfortunately MyBB doesn't have a cache for announcements // so we can have fun and double query! global $db; $fid = $db->fetch_field($db->simple_select('announcements', 'fid', 'aid=' . $aid), 'fid'); // note, $fid can be 0, for invalid aid, or announcement applying to all forums } break; default: return; } $fid = (int) $fid; // paranoia if ($fid) { global $forum; $forum = get_forum($fid); if (function_exists('xthreads_evalcacheForums')) { $xtforum = xthreads_evalcacheForums($fid); if ($xtforum['tplprefix'] !== '') { // this forum has a custom tpl prefix, hook into templates system control_object($templates, ' function cache($templates) { xthreads_tpl_cache($templates, $this); } function get($title, $eslashes=1, $htmlcomments=1) { xthreads_tpl_get($this, $title); return parent::get($title, $eslashes, $htmlcomments); } '); $templates->non_existant_templates = array(); $templates->xt_tpl_prefix = $xtforum['tplprefix']; } if ($xtforum['langprefix'] !== '') { global $lang; // this forum has a custom lang prefix, hook into lang system control_object($lang, ' function load($section, $isdatahandler=false, $supress_error=false) { $this->__xt_load($section, $isdatahandler, $supress_error); foreach($this->__xt_lang_prefix as &$pref) if($pref !== \'\') $this->__xt_load($pref.$section, $isdatahandler, true); } function __xt_load($section, $isdatahandler=false, $supress_error=false) { return parent::load($section, $isdatahandler, $supress_error); } '); $lang->__xt_lang_prefix = $xtforum['langprefix']; // load global lang messages that we couldn't before foreach ($lang->__xt_lang_prefix as &$pref) { if ($pref !== '' && preg_match('~^[a-zA-Z0-9_]+$~', $pref)) { $lang->__xt_load($pref . 'global', false, true); $lang->__xt_load($pref . 'messages', false, true); } } } if ($xtforum['settingoverrides'] !== '') { foreach ($xtforum['settingoverrides'] as $k => &$v) { $mybb->settings[$k] = $v; } } } //if($forum['xthreads_firstpostattop']) { switch ($current_page) { case 'showthread.php': require_once MYBB_ROOT . 'inc/xthreads/xt_sthreadhooks.php'; xthreads_showthread_firstpost(); break; case 'newthread.php': case 'editpost.php': if ($mybb->input['previewpost']) { $do_preload = true; if ($current_page == 'editpost.php') { global $thread; // check if first post $post = get_post((int) $mybb->input['pid']); if (!empty($post)) { $thread = get_thread($post['tid']); } $do_preload = !empty($thread) && $thread['firstpost'] == $post['pid']; } if ($do_preload) { require_once MYBB_ROOT . 'inc/xthreads/xt_sthreadhooks.php'; xthreads_firstpost_tpl_preload(); } break; } } //} // settings overrides if ($forum['xthreads_postsperpage']) { $mybb->settings['postsperpage'] = $forum['xthreads_postsperpage']; } // cache some more templates if necessary switch ($current_page) { case 'forumdisplay.php': if ($forum['xthreads_grouping']) { $templatelist .= ',forumdisplay_group_sep,forumdisplay_thread_null'; } if ($forum['xthreads_inlinesearch']) { $templatelist .= ',forumdisplay_searchforum_inline'; } if (function_exists('quickthread_run')) { // Quick Thread plugin $templatelist .= ',post_threadfields_inputrow'; } break; case 'editpost.php': $templatelist .= ',editpost_first'; case 'newthread.php': $templatelist .= ',post_threadfields_inputrow'; case 'showthread.php': $templatelist .= ',showthread_threadfields,showthread_threadfield_row'; break; } // hide breadcrumb business if ($current_page != 'printthread.php') { xthreads_breadcrumb_hack($fid); } else { // printthread needs some whacky attention $GLOBALS['plugins']->add_hook('printthread_start', 'xthreads_breadcrumb_hack_printthread', 10, MYBB_ROOT . 'inc/xthreads/xt_mischooks.php'); } xthreads_set_threadforum_urlvars('forum', $forum['fid']); } if (isset($set_thread_urlvar)) { xthreads_set_threadforum_urlvars('thread', $set_thread_urlvar); // since it's convenient... } }
function xthreads_moderation_custom() { //if($tool['type'] != 't') return; if (!is_object($GLOBALS['custommod'])) { return; } control_object($GLOBALS['custommod'], ' function execute_thread_moderation($thread_options, $tids) { if($thread_options[\'deletethread\'] != 1) xthreads_moderation_custom_do($tids, $thread_options[\'edit_threadfields\']); return parent::execute_thread_moderation($thread_options, $tids); } '); // this function is executed before copy thread (yay!) function xthreads_moderation_custom_do(&$tids, $editstr) { if (!$editstr) { return; } $edits = array(); // caching stuff static $threadfields = null; if (!isset($threadfields)) { $threadfields = xthreads_gettfcache(); } // grab all threadfields require_once MYBB_ROOT . 'inc/xthreads/xt_phptpl_lib.php'; foreach (explode("\n", str_replace("{\n}", "\r", str_replace("\r", '', $editstr))) as $editline) { $editline = trim(str_replace("\r", "\n", $editline)); list($n, $v) = explode('=', $editline, 2); if (!isset($v)) { continue; } // don't allow editing of file fields if (!isset($threadfields[$n]) || $threadfields[$n]['inputtype'] == XTHREADS_INPUT_FILE) { continue; } // we don't do much validation here as we trust admins, right? // this is just a prelim check (speed optimisation) - we'll need to check this again after evaluating conditionals $upperv = strtoupper($v); if (($upperv === '' || $upperv == 'NULL' || $upperv == 'NUL') && $threadfields[$n]['datatype'] != XTHREADS_DATATYPE_TEXT) { $edits[$n] = null; } else { $edits[$n] = $v; xthreads_sanitize_eval($edits[$n], array('VALUE' => null, 'TID' => null)); } } if (empty($edits)) { return; } $modfields = array_keys($edits); global $db; $query = $db->query(' SELECT t.tid, tfd.`' . implode('`, tfd.`', $modfields) . '` FROM ' . TABLE_PREFIX . 'threads t LEFT JOIN ' . TABLE_PREFIX . 'threadfields_data tfd ON t.tid=tfd.tid WHERE t.tid IN (' . implode(',', $tids) . ') '); //$query = $db->simple_select('threadfields_data', 'tid,`'.implode('`,`', $modfields).'`', 'tid IN ('.implode(',', $tids).')'); while ($thread = $db->fetch_array($query)) { $updates = array(); foreach ($edits as $n => $v) { if ($v !== null) { // TODO: allowing conditionals direct access to multivals? $v = trim(eval_str($v, array('VALUE' => $thread[$n], 'TID' => $thread['tid']))); if ($threadfields[$n]['datatype'] != XTHREADS_DATATYPE_TEXT) { $upperv = strtoupper($v); if ($upperv == '' || $upperv == 'NULL' || $upperv == 'NUL') { $v = null; } // TODO: intval/floatval here? } } if ($v !== $thread[$n]) { // we'll do some basic validation for multival fields if (!xthreads_empty($threadfields[$n]['multival'])) { $d = "\n"; if ($threadfields[$n]['inputtype'] == XTHREADS_INPUT_TEXT) { $d = ','; } $v = array_unique(array_map('trim', explode($d, str_replace("\r", '', $v)))); foreach ($v as $key => &$val) { if (xthreads_empty($val)) { unset($v[$key]); } } $v = implode($d, $v); } $updates[$n] = $v; } } if (!empty($updates)) { xthreads_db_update_replace('threadfields_data', $updates, 'tid', $thread['tid']); } } $db->free_result($query); } }
function xthreads_fix_stats() { global $cache; function &xthreads_fix_stats_read($stats, $hard) { static $fix = null; if (!isset($fix) || $hard) { $fix = array('posts' => 0, 'threads' => 0); $forums = $GLOBALS['cache']->read('forums', $hard); $q = $comma = ''; foreach ($forums as &$f) { if ($f['xthreads_nostatcount']) { $q .= $comma . $f['fid']; $comma = ','; } } // since MyBB doesn't cache forum counters, we have to query for it if ($q) { global $db; $fix = $db->fetch_array($db->simple_select('forums', 'SUM(threads)+SUM(unapprovedthreads) AS threads, SUM(posts)+SUM(unapprovedposts) AS posts', 'fid IN (' . $q . ')')); } } $stats['numposts'] -= $fix['posts']; $stats['numthreads'] -= $fix['threads']; return $stats; } control_object($cache, ' function read($name, $hard=false) { if($name != "stats") return parent::read($name, $hard); else return xthreads_fix_stats_read(parent::read($name, $hard), $hard); } '); }
function dispname_admin_unlock() { if (!$GLOBALS['mybb']->input['username']) { return; } control_object($GLOBALS['db'], ' function simple_select($table, $fields="*", $conditions="", $options=array()) { static $done = false; if(!$done && $table == "users" && $fields == "*") { if(substr($conditions, 0, 10) == "username=\'") { $conditions = "loginname".substr($conditions, 8); $done = true; } elseif(substr($conditions, 0, 16) == "LOWER(username)=\'") { $conditions = "LOWER(loginname)".substr($conditions, 14); $done = true; } } return parent::simple_select($table, $fields, $conditions, $options); } '); }
function spamalyser_after_post_hook(&$ph) { global $plugins; $plugins->remove_hook('datahandler_post_insert_post', 'spamalyser_after_post_hook'); $plugins->remove_hook('datahandler_post_insert_thread_post', 'spamalyser_after_post_hook'); control_object($GLOBALS['db'], ' function insert_query($table, $array) { static $done=false; if(!$done && $table == "posts") { $done=true; $pid = parent::insert_query($table, $array); _spamalyser_after_post_hook($pid, $this->spamalyser_ph); return $pid; } return parent::insert_query($table, $array); } '); $GLOBALS['db']->spamalyser_ph =& $ph; }