Exemplo n.º 1
0
/**
 * Marks all forums as read.
 *
 */
function mark_all_forums_read()
{
    global $mybb, $db, $cache;
    // Can only do "true" tracking for registered users
    if ($mybb->user['uid'] > 0) {
        $db->update_query("users", array('lastvisit' => TIME_NOW), "uid='" . $mybb->user['uid'] . "'");
        require_once MYBB_ROOT . "inc/functions_user.php";
        update_pm_count('', 2);
        if ($mybb->settings['threadreadcut'] > 0) {
            // Need to loop through all forums and mark them as read
            $forums = $cache->read('forums');
            $update_count = ceil(count($forums) / 20);
            if ($update_count < 15) {
                $update_count = 15;
            }
            $mark_query = '';
            $done = 0;
            foreach (array_keys($forums) as $fid) {
                switch ($db->type) {
                    case "pgsql":
                    case "sqlite":
                        $mark_query[] = array('fid' => $fid, 'uid' => $mybb->user['uid'], 'dateline' => TIME_NOW);
                        break;
                    default:
                        if ($mark_query != '') {
                            $mark_query .= ',';
                        }
                        $mark_query .= "('{$fid}', '{$mybb->user['uid']}', '" . TIME_NOW . "')";
                }
                ++$done;
                // Only do this in loops of $update_count, save query time
                if ($done % $update_count) {
                    switch ($db->type) {
                        case "pgsql":
                        case "sqlite":
                            foreach ($mark_query as $replace_query) {
                                add_shutdown(array($db, "replace_query"), array("forumsread", $replace_query, array("fid", "uid")));
                            }
                            $mark_query = array();
                            break;
                        default:
                            $db->shutdown_query("\n\t\t\t\t\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "forumsread (fid, uid, dateline)\n\t\t\t\t\t\t\t\tVALUES {$mark_query}\n\t\t\t\t\t\t\t");
                            $mark_query = '';
                    }
                }
            }
            if ($mark_query != '') {
                switch ($db->type) {
                    case "pgsql":
                    case "sqlite":
                        foreach ($mark_query as $replace_query) {
                            add_shutdown(array($db, "replace_query"), array("forumsread", $replace_query, array("fid", "uid")));
                        }
                        break;
                    default:
                        $db->shutdown_query("\n\t\t\t\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "forumsread (fid, uid, dateline)\n\t\t\t\t\t\t\tVALUES {$mark_query}\n\t\t\t\t\t\t");
                }
            }
        }
    } else {
        my_setcookie("mybb[readallforums]", 1);
        my_setcookie("mybb[lastvisit]", TIME_NOW);
        my_unsetcookie("mybb[threadread]");
        my_unsetcookie("mybb[forumread]");
    }
}
Exemplo n.º 2
0
$lang->set_language($mybb->settings['bblanguage']);
$lang->load("global");
$lang->load("messages");
if (function_exists('mb_internal_encoding') && !empty($lang->settings['charset'])) {
    @mb_internal_encoding($lang->settings['charset']);
}
require_once MYBB_ROOT . "inc/functions_task.php";
// Are tasks set to run via cron instead & are we accessing this file via the CLI?
// php task.php [tid]
if (PHP_SAPI == "cli") {
    // Passing a specific task ID
    if ($_SERVER['argc'] == 2) {
        $query = $db->simple_select("tasks", "tid", "tid='" . intval($_SERVER['argv'][1]) . "'");
        $tid = $db->fetch_field($query, "tid");
    }
    if ($tid) {
        run_task($tid);
    } else {
        run_task();
    }
} else {
    // Send our fake gif image (clear 1x1 transparent image)
    header("Content-type: image/gif");
    echo base64_decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");
    // If the use shutdown functionality is turned off, run any shutdown related items now.
    if ($mybb->settings['useshutdownfunc'] != 0 || $mybb->use_shutdown == true) {
        add_shutdown("run_task");
    } else {
        run_task();
    }
}
Exemplo n.º 3
0
    register_shutdown_function('run_shutdown');
}
// Did we just upgrade to a new version and haven't run the upgrade scripts yet?
$version = $cache->read("version");
if (!defined("IN_INSTALL") && !defined("IN_UPGRADE") && $version['version_code'] < $mybb->version_code) {
    $version_history = $cache->read("version_history");
    if (empty($version_history) || file_exists(MYBB_ROOT . "install/resources/upgrade" . (int) (end($version_history) + 1) . ".php")) {
        $mybb->trigger_generic_error("board_not_upgraded");
    }
}
// Load plugins
if (!defined("NO_PLUGINS") && !($mybb->settings['no_plugins'] == 1)) {
    $plugins->load();
}
// Set up any shutdown functions we need to run globally
add_shutdown('send_mail_queue');
/* URL Definitions */
if ($mybb->settings['seourls'] == "yes" || $mybb->settings['seourls'] == "auto" && isset($_SERVER['SEO_SUPPORT']) && $_SERVER['SEO_SUPPORT'] == 1) {
    $mybb->seo_support = true;
    define('FORUM_URL', "forum-{fid}.html");
    define('FORUM_URL_PAGED', "forum-{fid}-page-{page}.html");
    define('THREAD_URL', "thread-{tid}.html");
    define('THREAD_URL_PAGED', "thread-{tid}-page-{page}.html");
    define('THREAD_URL_ACTION', 'thread-{tid}-{action}.html');
    define('THREAD_URL_POST', 'thread-{tid}-post-{pid}.html');
    define('POST_URL', "post-{pid}.html");
    define('PROFILE_URL', "user-{uid}.html");
    define('ANNOUNCEMENT_URL', "announcement-{aid}.html");
    define('CALENDAR_URL', "calendar-{calendar}.html");
    define('CALENDAR_URL_MONTH', 'calendar-{calendar}-year-{year}-month-{month}.html');
    define('CALENDAR_URL_DAY', 'calendar-{calendar}-year-{year}-month-{month}-day-{day}.html');
Exemplo n.º 4
0
 function newpoints_perview()
 {
     global $db, $mybb, $cache, $groupscache, $userupdates;
     if (!$mybb->user['uid']) {
         return;
     }
     if ($mybb->settings['newpoints_main_enabled'] != 1) {
         return;
     }
     // check group rules - primary group check
     $grouprules = newpoints_getallrules('group');
     if (empty($grouprules)) {
         return;
     }
     if ($mybb->settings['newpoints_income_pageview'] != 0) {
         newpoints_addpoints($mybb->user['uid'], $mybb->settings['newpoints_income_pageview'], 1, $grouprules[$mybb->user['usergroup']]['rate']);
     }
     if ($mybb->settings['newpoints_income_visit'] != 0) {
         if (TIME_NOW - $mybb->user['lastactive'] > 900) {
             newpoints_addpoints($mybb->user['uid'], $mybb->settings['newpoints_income_visit'], 1, $grouprules[$mybb->user['usergroup']]['rate']);
         }
     }
     foreach ($grouprules as $gid => $rule) {
         if ($rule['pointsearn'] == 0 || $rule['period'] == 0 || $rule['lastpay'] > TIME_NOW - $rule['period']) {
             return;
         }
         //die("testing".$rule['pointsearn']." | ".$rule['period']." | ".$rule['lastpay']." | ".TIME_NOW);
         $amount = floatval($rule['pointsearn']);
         $userupdates[$gid] = $amount;
         // update rule with last payment
         $db->update_query('newpoints_grouprules', array('lastpay' => TIME_NOW), 'gid=\'' . $gid . '\'');
         if ($mybb->user['usergroup'] == $gid) {
             $mybb->user['newpoints'] += $amount;
         }
         if (!empty($userupdates)) {
             // run updates to users on shut down
             add_shutdown('newpoints_update_users');
         }
     }
 }
Exemplo n.º 5
0
function upgrade5_indexes()
{
    global $db, $output;
    $output->print_header("Indexing");
    echo "<p>Checking and creating fulltext database indexes..</p>";
    if ($db->is_fulltext("threads", "subject")) {
        $db->drop_index("threads", "subject");
    }
    if ($db->is_fulltext("threads", "subject_2")) {
        $db->drop_index("threads", "subject_2");
    }
    if ($db->supports_fulltext("threads")) {
        $db->create_fulltext_index("threads", "subject");
    }
    if ($db->supports_fulltext_boolean("posts")) {
        if (!$db->is_fulltext("posts", "message")) {
            $db->create_fulltext_index("posts", "message");
        }
    }
    // Register a shutdown function which actually tests if this functionality is working
    add_shutdown('test_shutdown_function');
    $contents .= "Click next to continue with the upgrade process.</p>";
    $output->print_contents($contents);
    $output->print_footer("5_done");
}
Exemplo n.º 6
0
/**
 * Adds/Subtracts points to a user
 * 
 * @param integer the id of the user
 * @param float the number of points to add or subtract (if a negative value)
 * @param integer the forum income rate
 * @param integer the user group income rate
 * @param bool if the uid is a string in case we don't have the uid we can update the points field by searching for the user name
 * @param bool true if you want to run the query immediatly. Default is false which means the query will be run on shut down. Note that if the previous paremeter is set to true, the query is run immediatly
 * Note: some pages (by other plugins) do not run queries on shutdown so adding this to shutdown may not be good if you're not sure if it will run.
 *
*/
function newpoints_addpoints($uid, $points, $forumrate = 1, $grouprate = 1, $isstring = false, $immediate = false)
{
    global $db, $mybb, $userpoints;
    if ($points == 0 || $uid <= 0 && !$isstring) {
        return;
    }
    if ($isstring === true) {
        $immediate = true;
    }
    // might work only for MySQL and MySQLi
    //$db->update_query("users", array('newpoints' => 'newpoints+('.floatval($points).')'), 'uid=\''.intval($uid).'\'', '', true);
    if ($isstring) {
        // where username
        $db->write_query("UPDATE " . TABLE_PREFIX . "users SET newpoints=newpoints+'" . floatval(round($points * $forumrate * $grouprate, intval($mybb->settings['newpoints_main_decimal']))) . "' WHERE username='******'");
    } else {
        // if immediate, run the query now otherwise add it to shutdown to avoid slow down
        if ($immediate) {
            $db->write_query("UPDATE " . TABLE_PREFIX . "users SET newpoints=newpoints+'" . floatval(round($points * $forumrate * $grouprate, intval($mybb->settings['newpoints_main_decimal']))) . "' WHERE uid='" . intval($uid) . "'");
        } else {
            $userpoints[intval($uid)] += floatval(round($points * $forumrate * $grouprate, intval($mybb->settings['newpoints_main_decimal'])));
        }
    }
    static $newpoints_shutdown;
    if (!isset($newpoints_shutdown)) {
        $newpoints_shutdown = true;
        add_shutdown('newpoints_update_addpoints');
    }
}
Exemplo n.º 7
0
function install_done()
{
    global $output, $db, $mybb, $errors, $cache, $lang;
    if (empty($mybb->input['adminuser'])) {
        $errors[] = $lang->admin_step_error_nouser;
    }
    if (empty($mybb->input['adminpass'])) {
        $errors[] = $lang->admin_step_error_nopassword;
    }
    if ($mybb->input['adminpass'] != $mybb->input['adminpass2']) {
        $errors[] = $lang->admin_step_error_nomatch;
    }
    if (empty($mybb->input['adminemail'])) {
        $errors[] = $lang->admin_step_error_noemail;
    }
    if (is_array($errors)) {
        create_admin_user();
    }
    require MYBB_ROOT . 'inc/config.php';
    $db = db_connection($config);
    require MYBB_ROOT . 'inc/settings.php';
    $mybb->settings =& $settings;
    ob_start();
    $output->print_header($lang->finish_setup, 'finish');
    echo $lang->done_step_usergroupsinserted;
    // Insert all of our user groups from the XML file
    $settings = file_get_contents(INSTALL_ROOT . 'resources/usergroups.xml');
    $parser = new XMLParser($settings);
    $parser->collapse_dups = 0;
    $tree = $parser->get_tree();
    $admin_gid = '';
    $group_count = 0;
    foreach ($tree['usergroups'][0]['usergroup'] as $usergroup) {
        // usergroup[cancp][0][value]
        $new_group = array();
        foreach ($usergroup as $key => $value) {
            if ($key == "gid" || !is_array($value)) {
                continue;
            }
            $new_group[$key] = $db->escape_string($value[0]['value']);
        }
        $return_gid = $db->insert_query("usergroups", $new_group);
        // If this group can access the admin CP and we haven't established the admin group - set it (just in case we ever change IDs)
        if ($new_group['cancp'] == 1 && !$admin_gid) {
            $admin_gid = $return_gid;
        }
        $group_count++;
    }
    echo $lang->done . '</p>';
    echo $lang->done_step_admincreated;
    $now = TIME_NOW;
    $salt = random_str();
    $loginkey = generate_loginkey();
    $saltedpw = md5(md5($salt) . md5($mybb->input['adminpass']));
    $newuser = array('username' => $db->escape_string($mybb->input['adminuser']), 'password' => $saltedpw, 'salt' => $salt, 'loginkey' => $loginkey, 'email' => $db->escape_string($mybb->input['adminemail']), 'usergroup' => $admin_gid, 'regdate' => $now, 'lastactive' => $now, 'lastvisit' => $now, 'website' => '', 'icq' => '', 'aim' => '', 'yahoo' => '', 'msn' => '', 'birthday' => '', 'signature' => '', 'allownotices' => 1, 'hideemail' => 0, 'subscriptionmethod' => '0', 'receivepms' => 1, 'pmnotice' => 1, 'pmnotify' => 1, 'remember' => 1, 'showsigs' => 1, 'showavatars' => 1, 'showquickreply' => 1, 'invisible' => 0, 'style' => '0', 'timezone' => 0, 'dst' => 0, 'threadmode' => '', 'daysprune' => 0, 'regip' => $db->escape_string(get_ip()), 'longregip' => intval(ip2long(get_ip())), 'language' => '', 'showcodebuttons' => 1, 'tpp' => 0, 'ppp' => 0, 'referrer' => 0, 'buddylist' => '', 'ignorelist' => '', 'pmfolders' => '', 'notepad' => '', 'showredirect' => 1);
    $db->insert_query('users', $newuser);
    echo $lang->done . '</p>';
    echo $lang->done_step_adminoptions;
    $adminoptions = file_get_contents(INSTALL_ROOT . 'resources/adminoptions.xml');
    $parser = new XMLParser($adminoptions);
    $parser->collapse_dups = 0;
    $tree = $parser->get_tree();
    $insertmodule = array();
    $db->delete_query("adminoptions");
    // Insert all the admin permissions
    foreach ($tree['adminoptions'][0]['user'] as $users) {
        $uid = $users['attributes']['uid'];
        foreach ($users['permissions'][0]['module'] as $module) {
            foreach ($module['permission'] as $permission) {
                $insertmodule[$module['attributes']['name']][$permission['attributes']['name']] = $permission['value'];
            }
        }
        $defaultviews = array();
        foreach ($users['defaultviews'][0]['view'] as $view) {
            $defaultviews[$view['attributes']['type']] = $view['value'];
        }
        $adminoptiondata = array('uid' => intval($uid), 'cpstyle' => '', 'notes' => '', 'permissions' => $db->escape_string(serialize($insertmodule)), 'defaultviews' => $db->escape_string(serialize($defaultviews)));
        $insertmodule = array();
        $db->insert_query('adminoptions', $adminoptiondata);
    }
    echo $lang->done . '</p>';
    // Automatic Login
    my_unsetcookie("sid");
    my_unsetcookie("mybbuser");
    my_setcookie('mybbuser', $uid . '_' . $loginkey, null, true);
    ob_end_flush();
    // Make fulltext columns if supported
    if ($db->supports_fulltext('threads')) {
        $db->create_fulltext_index('threads', 'subject');
    }
    if ($db->supports_fulltext_boolean('posts')) {
        $db->create_fulltext_index('posts', 'message');
    }
    // Register a shutdown function which actually tests if this functionality is working
    add_shutdown('test_shutdown_function');
    echo $lang->done_step_cachebuilding;
    require_once MYBB_ROOT . 'inc/class_datacache.php';
    $cache = new datacache();
    $cache->update_version();
    $cache->update_attachtypes();
    $cache->update_smilies();
    $cache->update_badwords();
    $cache->update_usergroups();
    $cache->update_forumpermissions();
    $cache->update_stats();
    $cache->update_forums();
    $cache->update_moderators();
    $cache->update_usertitles();
    $cache->update_reportedposts();
    $cache->update_mycode();
    $cache->update_posticons();
    $cache->update_update_check();
    $cache->update_tasks();
    $cache->update_spiders();
    $cache->update_bannedips();
    $cache->update_banned();
    $cache->update_birthdays();
    $cache->update("plugins", array());
    $cache->update("internal_settings", array('encryption_key' => random_str(32)));
    echo $lang->done . '</p>';
    echo $lang->done_step_success;
    $written = 0;
    if (is_writable('./')) {
        $lock = @fopen('./lock', 'w');
        $written = @fwrite($lock, '1');
        @fclose($lock);
        if ($written) {
            echo $lang->done_step_locked;
        }
    }
    if (!$written) {
        echo $lang->done_step_dirdelete;
    }
    echo $lang->done_subscribe_mailing;
    $output->print_footer('');
}
Exemplo n.º 8
0
/**
 * Updates the forum statistics with specific values (or addition/subtraction of the previous value)
 *
 * @param array $changes Array of items being updated (numthreads,numposts,numusers,numunapprovedthreads,numunapprovedposts,numdeletedposts,numdeletedthreads)
 * @param boolean $force Force stats update?
 */
function update_stats($changes = array(), $force = false)
{
    global $cache, $db;
    static $stats_changes;
    if (empty($stats_changes)) {
        // Update stats after all changes are done
        add_shutdown('update_stats', array(array(), true));
    }
    if (empty($stats_changes) || $stats_changes['inserted']) {
        $stats_changes = array('numthreads' => '+0', 'numposts' => '+0', 'numusers' => '+0', 'numunapprovedthreads' => '+0', 'numunapprovedposts' => '+0', 'numdeletedposts' => '+0', 'numdeletedthreads' => '+0', 'inserted' => false);
        $stats = $stats_changes;
    }
    if ($force) {
        if (!empty($changes)) {
            // Calculate before writing to cache
            update_stats($changes);
        }
        $stats = $cache->read("stats");
        $changes = $stats_changes;
    } else {
        $stats = $stats_changes;
    }
    $new_stats = array();
    $counters = array('numthreads', 'numunapprovedthreads', 'numposts', 'numunapprovedposts', 'numusers', 'numdeletedposts', 'numdeletedthreads');
    foreach ($counters as $counter) {
        if (array_key_exists($counter, $changes)) {
            if (substr($changes[$counter], 0, 2) == "+-") {
                $changes[$counter] = substr($changes[$counter], 1);
            }
            // Adding or subtracting from previous value?
            if (substr($changes[$counter], 0, 1) == "+" || substr($changes[$counter], 0, 1) == "-") {
                if ((int) $changes[$counter] != 0) {
                    $new_stats[$counter] = $stats[$counter] + $changes[$counter];
                    if (!$force && (substr($stats[$counter], 0, 1) == "+" || substr($stats[$counter], 0, 1) == "-")) {
                        // We had relative values? Then it is still relative
                        if ($new_stats[$counter] >= 0) {
                            $new_stats[$counter] = "+{$new_stats[$counter]}";
                        }
                    } elseif ($new_stats[$counter] < 0) {
                        $new_stats[$counter] = 0;
                    }
                }
            } else {
                $new_stats[$counter] = $changes[$counter];
                // Less than 0? That's bad
                if ($new_stats[$counter] < 0) {
                    $new_stats[$counter] = 0;
                }
            }
        }
    }
    if (!$force) {
        $stats_changes = array_merge($stats, $new_stats);
        // Overwrite changed values
        return;
    }
    // Fetch latest user if the user count is changing
    if (array_key_exists('numusers', $changes)) {
        $query = $db->simple_select("users", "uid, username", "", array('order_by' => 'regdate', 'order_dir' => 'DESC', 'limit' => 1));
        $lastmember = $db->fetch_array($query);
        $new_stats['lastuid'] = $lastmember['uid'];
        $new_stats['lastusername'] = $lastmember['username'];
    }
    if (!empty($new_stats)) {
        if (is_array($stats)) {
            $stats = array_merge($stats, $new_stats);
            // Overwrite changed values
        } else {
            $stats = $new_stats;
        }
    }
    // Update stats row for today in the database
    $todays_stats = array("dateline" => mktime(0, 0, 0, date("m"), date("j"), date("Y")), "numusers" => $stats['numusers'], "numthreads" => $stats['numthreads'], "numposts" => $stats['numposts']);
    $db->replace_query("stats", $todays_stats, "dateline");
    $cache->update("stats", $stats, "dateline");
    $stats_changes['inserted'] = true;
}