/** * Execute a scheduled task. * * @param int $tid The task ID. If none specified, the next task due to be ran is executed * @return boolean True if successful, false on failure */ function run_task($tid = 0) { global $db, $mybb, $cache, $plugins, $task, $lang; // Run a specific task if ($tid > 0) { $query = $db->simple_select("tasks", "*", "tid='{$tid}'"); $task = $db->fetch_array($query); } else { $query = $db->simple_select("tasks", "*", "enabled=1 AND nextrun<='" . TIME_NOW . "'", array("order_by" => "nextrun", "order_dir" => "asc", "limit" => 1)); $task = $db->fetch_array($query); } // No task? Return if (!$task['tid']) { $cache->update_tasks(); return false; } // Is this task still running and locked less than 5 minutes ago? Well don't run it now - clearly it isn't broken! if ($task['locked'] != 0 && $task['locked'] > TIME_NOW - 300) { $cache->update_tasks(); return false; } else { $db->update_query("tasks", array("locked" => TIME_NOW), "tid='{$task['tid']}'"); } // The task file does not exist if (!file_exists(MYBB_ROOT . "inc/tasks/{$task['file']}.php")) { if ($task['logging'] == 1) { add_task_log($task, $lang->missing_task); } // If task file does not exist, disable task and inform the administrator $updated_task = array("enabled" => 0, "locked" => 0); $db->update_query("tasks", $updated_task, "tid='{$task['tid']}'"); $subject = $lang->sprintf($lang->email_broken_task_subject, $mybb->settings['bbname']); $message = $lang->sprintf($lang->email_broken_task, $mybb->settings['bbname'], $mybb->settings['bburl'], $task['title']); my_mail($mybb->settings['adminemail'], $subject, $message, $mybb->settings['adminemail']); $cache->update_tasks(); return false; } else { // Update the nextrun time now, so if the task causes a fatal error, it doesn't get stuck first in the queue $nextrun = fetch_next_run($task); $db->update_query("tasks", array("nextrun" => $nextrun), "tid='{$task['tid']}'"); include_once MYBB_ROOT . "inc/tasks/{$task['file']}.php"; $function = "task_{$task['file']}"; if (function_exists($function)) { $function($task); } } $updated_task = array("lastrun" => TIME_NOW, "locked" => 0); $db->update_query("tasks", $updated_task, "tid='{$task['tid']}'"); $cache->update_tasks(); return true; }
function purgesoftdeleted_activate() { global $db, $cache; // Create task - Purge soft deleted // Have we already added this task? $query = $db->simple_select('tasks', 'tid', "file='purgesoftdeleted'", array('limit' => '1')); if ($db->num_rows($query) == 0) { // Load tasks function needed to run a task and add nextrun time require_once MYBB_ROOT . "/inc/functions_task.php"; // If not then add $new_task = array("title" => "Purge soft deleted posts and threads", "description" => "Checks for soft deleted posts and threads and purges them automatically.", "file" => "purgesoftdeleted", "minute" => '2', "hour" => '0', "day" => '*', "month" => '*', "weekday" => '*', "enabled" => '1', "logging" => '1'); $new_task['nextrun'] = fetch_next_run($new_task); $tid = $db->insert_query("tasks", $new_task); // Update the task and run it right now $cache->update_tasks(); run_task($tid); } }
/** * How do we want to name the admin user? */ function create_admin_user() { global $output, $mybb, $errors, $db, $lang; $mybb->input['action'] = "adminuser"; // If no errors then check for errors from last step if (!is_array($errors)) { if (empty($mybb->input['bburl'])) { $errors[] = $lang->config_step_error_url; } if (empty($mybb->input['bbname'])) { $errors[] = $lang->config_step_error_name; } if (is_array($errors)) { configure(); } } $output->print_header($lang->create_admin, 'admin'); echo <<<EOF \t\t<script type="text/javascript">\t \t\tfunction comparePass() \t\t{ \t\t\tvar parenttr = \$('#adminpass2').closest('tr'); \t\t\tvar passval = \$('#adminpass2').val(); \t\t\tif(passval && passval != \$('#adminpass').val()) \t\t\t{ \t\t\t\tif(!parenttr.next('.pass_peeker').length) \t\t\t\t{ \t\t\t\t\tparenttr.removeClass('last').after('<tr class="pass_peeker"><td colspan="2">{$lang->admin_step_nomatch}</td></tr>'); \t\t\t\t} \t\t\t} else { \t\t\t\tparenttr.addClass('last').next('.pass_peeker').remove(); \t\t\t} \t\t} \t\t</script> \t\t EOF; if (is_array($errors)) { $error_list = error_list($errors); echo $lang->sprintf($lang->admin_step_error_config, $error_list); $adminuser = $mybb->get_input('adminuser'); $adminemail = $mybb->get_input('adminemail'); } else { require MYBB_ROOT . 'inc/config.php'; $db = db_connection($config); echo $lang->admin_step_setupsettings; $adminuser = $adminemail = ''; $settings = file_get_contents(INSTALL_ROOT . 'resources/settings.xml'); $parser = new XMLParser($settings); $parser->collapse_dups = 0; $tree = $parser->get_tree(); $groupcount = $settingcount = 0; // Insert all the settings foreach ($tree['settings'][0]['settinggroup'] as $settinggroup) { $groupdata = array('name' => $db->escape_string($settinggroup['attributes']['name']), 'title' => $db->escape_string($settinggroup['attributes']['title']), 'description' => $db->escape_string($settinggroup['attributes']['description']), 'disporder' => (int) $settinggroup['attributes']['disporder'], 'isdefault' => $settinggroup['attributes']['isdefault']); $gid = $db->insert_query('settinggroups', $groupdata); ++$groupcount; foreach ($settinggroup['setting'] as $setting) { $settingdata = array('name' => $db->escape_string($setting['attributes']['name']), 'title' => $db->escape_string($setting['title'][0]['value']), 'description' => $db->escape_string($setting['description'][0]['value']), 'optionscode' => $db->escape_string($setting['optionscode'][0]['value']), 'value' => $db->escape_string($setting['settingvalue'][0]['value']), 'disporder' => (int) $setting['disporder'][0]['value'], 'gid' => $gid, 'isdefault' => 1); $db->insert_query('settings', $settingdata); $settingcount++; } } if (my_substr($mybb->get_input('bburl'), -1, 1) == '/') { $mybb->input['bburl'] = my_substr($mybb->get_input('bburl'), 0, -1); } $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('bbname'))), "name='bbname'"); $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('bburl'))), "name='bburl'"); $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('websitename'))), "name='homename'"); $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('websiteurl'))), "name='homeurl'"); $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('cookiedomain'))), "name='cookiedomain'"); $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('cookiepath'))), "name='cookiepath'"); $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('contactemail'))), "name='adminemail'"); $db->update_query("settings", array('value' => 'contact.php'), "name='contactlink'"); write_settings(); echo $lang->sprintf($lang->admin_step_insertesettings, $settingcount, $groupcount); // Save the acp pin $pin = addslashes($mybb->get_input('pin')); $file = @fopen(MYBB_ROOT . "inc/config.php", "a"); @fwrite($file, "/**\n * Admin CP Secret PIN\n * If you wish to request a PIN\n * when someone tries to login\n * on your Admin CP, enter it below.\n */\n\n\$config['secret_pin'] = '{$pin}';"); @fclose($file); include_once MYBB_ROOT . "inc/functions_task.php"; $tasks = file_get_contents(INSTALL_ROOT . 'resources/tasks.xml'); $parser = new XMLParser($tasks); $parser->collapse_dups = 0; $tree = $parser->get_tree(); $taskcount = 0; // Insert scheduled tasks foreach ($tree['tasks'][0]['task'] as $task) { $new_task = array('title' => $db->escape_string($task['title'][0]['value']), 'description' => $db->escape_string($task['description'][0]['value']), 'file' => $db->escape_string($task['file'][0]['value']), 'minute' => $db->escape_string($task['minute'][0]['value']), 'hour' => $db->escape_string($task['hour'][0]['value']), 'day' => $db->escape_string($task['day'][0]['value']), 'weekday' => $db->escape_string($task['weekday'][0]['value']), 'month' => $db->escape_string($task['month'][0]['value']), 'enabled' => $db->escape_string($task['enabled'][0]['value']), 'logging' => $db->escape_string($task['logging'][0]['value'])); $new_task['nextrun'] = fetch_next_run($new_task); $db->insert_query("tasks", $new_task); $taskcount++; } // For the version check task, set a random date and hour (so all MyBB installs don't query mybb.com all at the same time) $update_array = array('hour' => rand(0, 23), 'weekday' => rand(0, 6)); $db->update_query("tasks", $update_array, "file = 'versioncheck'"); echo $lang->sprintf($lang->admin_step_insertedtasks, $taskcount); $views = file_get_contents(INSTALL_ROOT . 'resources/adminviews.xml'); $parser = new XMLParser($views); $parser->collapse_dups = 0; $tree = $parser->get_tree(); $view_count = 0; // Insert admin views foreach ($tree['adminviews'][0]['view'] as $view) { $fields = array(); foreach ($view['fields'][0]['field'] as $field) { $fields[] = $field['attributes']['name']; } $conditions = array(); if (isset($view['conditions'][0]['condition']) && is_array($view['conditions'][0]['condition'])) { foreach ($view['conditions'][0]['condition'] as $condition) { if (!$condition['value']) { continue; } if ($condition['attributes']['is_serialized'] == 1) { $condition['value'] = my_unserialize($condition['value']); } $conditions[$condition['attributes']['name']] = $condition['value']; } } $custom_profile_fields = array(); if (isset($view['custom_profile_fields'][0]['field']) && is_array($view['custom_profile_fields'][0]['field'])) { foreach ($view['custom_profile_fields'][0]['field'] as $field) { $custom_profile_fields[] = $field['attributes']['name']; } } $new_view = array("uid" => 0, "type" => $db->escape_string($view['attributes']['type']), "visibility" => (int) $view['attributes']['visibility'], "title" => $db->escape_string($view['title'][0]['value']), "fields" => $db->escape_string(my_serialize($fields)), "conditions" => $db->escape_string(my_serialize($conditions)), "custom_profile_fields" => $db->escape_string(my_serialize($custom_profile_fields)), "sortby" => $db->escape_string($view['sortby'][0]['value']), "sortorder" => $db->escape_string($view['sortorder'][0]['value']), "perpage" => (int) $view['perpage'][0]['value'], "view_type" => $db->escape_string($view['view_type'][0]['value'])); $db->insert_query("adminviews", $new_view); $view_count++; } echo $lang->sprintf($lang->admin_step_insertedviews, $view_count); echo $lang->admin_step_createadmin; } echo $lang->sprintf($lang->admin_step_admintable, $adminuser, $adminemail); $output->print_footer('final'); }
admin_redirect("index.php?module=tools/tasks"); } if ($mybb->request_method == "post") { $nextrun = fetch_next_run($task); $db->update_query("tasks", array("nextrun" => $nextrun, "enabled" => 1), "tid='{$task['tid']}'"); $cache->update_tasks(); $plugins->run_hooks("admin_tools_tasks_enable_commit"); // Log admin action log_admin_action($task['tid'], $task['title'], $mybb->input['action']); flash_message($lang->success_task_enabled, 'success'); admin_redirect("index.php?module=tools/tasks"); } else { $page->output_confirm_action("index.php?module=tools/tasks&action=enable&tid={$task['tid']}", $lang->confirm_task_enable); } } else { $nextrun = fetch_next_run($task); $db->update_query("tasks", array("nextrun" => $nextrun, "enabled" => 1), "tid='{$task['tid']}'"); $cache->update_tasks(); $plugins->run_hooks("admin_tools_tasks_enable_commit"); // Log admin action log_admin_action($task['tid'], $task['title'], $mybb->input['action']); flash_message($lang->success_task_enabled, 'success'); admin_redirect("index.php?module=tools/tasks"); } } else { $db->update_query("tasks", array("enabled" => 0), "tid='{$task['tid']}'"); $cache->update_tasks(); $plugins->run_hooks("admin_tools_tasks_disable_commit"); // Log admin action log_admin_action($task['tid'], $task['title'], $mybb->input['action']); flash_message($lang->success_task_disabled, 'success');
function create_admin_user() { global $output, $mybb, $errors, $db, $lang; $mybb->input['action'] = "adminuser"; // If no errors then check for errors from last step if (!is_array($errors)) { if (empty($mybb->input['bburl'])) { $errors[] = $lang->config_step_error_url; } if (empty($mybb->input['bbname'])) { $errors[] = $lang->config_step_error_name; } if (is_array($errors)) { configure(); } } $output->print_header($lang->create_admin, 'admin'); if (is_array($errors)) { $error_list = error_list($errors); echo $lang->sprintf($lang->admin_step_error_config, $error_list); $adminuser = $mybb->input['adminuser']; $adminemail = $mybb->input['adminemail']; } else { require MYBB_ROOT . 'inc/config.php'; $db = db_connection($config); echo $lang->admin_step_setupsettings; $settings = file_get_contents(INSTALL_ROOT . 'resources/settings.xml'); $parser = new XMLParser($settings); $parser->collapse_dups = 0; $tree = $parser->get_tree(); // Insert all the settings foreach ($tree['settings'][0]['settinggroup'] as $settinggroup) { $groupdata = array('name' => $db->escape_string($settinggroup['attributes']['name']), 'title' => $db->escape_string($settinggroup['attributes']['title']), 'description' => $db->escape_string($settinggroup['attributes']['description']), 'disporder' => intval($settinggroup['attributes']['disporder']), 'isdefault' => $settinggroup['attributes']['isdefault']); $gid = $db->insert_query('settinggroups', $groupdata); ++$groupcount; foreach ($settinggroup['setting'] as $setting) { $settingdata = array('name' => $db->escape_string($setting['attributes']['name']), 'title' => $db->escape_string($setting['title'][0]['value']), 'description' => $db->escape_string($setting['description'][0]['value']), 'optionscode' => $db->escape_string($setting['optionscode'][0]['value']), 'value' => $db->escape_string($setting['settingvalue'][0]['value']), 'disporder' => intval($setting['disporder'][0]['value']), 'gid' => $gid, 'isdefault' => 1); $db->insert_query('settings', $settingdata); $settingcount++; } } if (my_substr($mybb->input['bburl'], -1, 1) == '/') { $mybb->input['bburl'] = my_substr($mybb->input['bburl'], 0, -1); } $db->update_query("settings", array('value' => $db->escape_string($mybb->input['bbname'])), "name='bbname'"); $db->update_query("settings", array('value' => $db->escape_string($mybb->input['bburl'])), "name='bburl'"); $db->update_query("settings", array('value' => $db->escape_string($mybb->input['websitename'])), "name='homename'"); $db->update_query("settings", array('value' => $db->escape_string($mybb->input['websiteurl'])), "name='homeurl'"); $db->update_query("settings", array('value' => $db->escape_string($mybb->input['cookiedomain'])), "name='cookiedomain'"); $db->update_query("settings", array('value' => $db->escape_string($mybb->input['cookiepath'])), "name='cookiepath'"); $db->update_query("settings", array('value' => $db->escape_string($mybb->input['contactemail'])), "name='adminemail'"); $db->update_query("settings", array('value' => 'mailto:' . $db->escape_string($mybb->input['contactemail'])), "name='contactlink'"); write_settings(); echo $lang->sprintf($lang->admin_step_insertesettings, $settingcount, $groupcount); include_once MYBB_ROOT . "inc/functions_task.php"; $tasks = file_get_contents(INSTALL_ROOT . 'resources/tasks.xml'); $parser = new XMLParser($tasks); $parser->collapse_dups = 0; $tree = $parser->get_tree(); // Insert scheduled tasks foreach ($tree['tasks'][0]['task'] as $task) { $new_task = array('title' => $db->escape_string($task['title'][0]['value']), 'description' => $db->escape_string($task['description'][0]['value']), 'file' => $db->escape_string($task['file'][0]['value']), 'minute' => $db->escape_string($task['minute'][0]['value']), 'hour' => $db->escape_string($task['hour'][0]['value']), 'day' => $db->escape_string($task['day'][0]['value']), 'weekday' => $db->escape_string($task['weekday'][0]['value']), 'month' => $db->escape_string($task['month'][0]['value']), 'enabled' => $db->escape_string($task['enabled'][0]['value']), 'logging' => $db->escape_string($task['logging'][0]['value'])); $new_task['nextrun'] = fetch_next_run($new_task); $db->insert_query("tasks", $new_task); $taskcount++; } echo $lang->sprintf($lang->admin_step_insertedtasks, $taskcount); $views = file_get_contents(INSTALL_ROOT . 'resources/adminviews.xml'); $parser = new XMLParser($views); $parser->collapse_dups = 0; $tree = $parser->get_tree(); // Insert admin views foreach ($tree['adminviews'][0]['view'] as $view) { $fields = array(); foreach ($view['fields'][0]['field'] as $field) { $fields[] = $field['attributes']['name']; } $conditions = array(); if (is_array($view['conditions'][0]['condition'])) { foreach ($view['conditions'][0]['condition'] as $condition) { if (!$condition['value']) { continue; } if ($condition['attributes']['is_serialized'] == 1) { $condition['value'] = unserialize($condition['value']); } $conditions[$condition['attributes']['name']] = $condition['value']; } } $custom_profile_fields = array(); if (is_array($view['custom_profile_fields'][0]['field'])) { foreach ($view['custom_profile_fields'][0]['field'] as $field) { $custom_profile_fields[] = $field['attributes']['name']; } } $new_view = array("uid" => 0, "type" => $db->escape_string($view['attributes']['type']), "visibility" => intval($view['attributes']['visibility']), "title" => $db->escape_string($view['title'][0]['value']), "fields" => $db->escape_string(serialize($fields)), "conditions" => $db->escape_string(serialize($conditions)), "custom_profile_fields" => $db->escape_string(serialize($custom_profile_fields)), "sortby" => $db->escape_string($view['sortby'][0]['value']), "sortorder" => $db->escape_string($view['sortorder'][0]['value']), "perpage" => intval($view['perpage'][0]['value']), "view_type" => $db->escape_string($view['view_type'][0]['value'])); $db->insert_query("adminviews", $new_view); $view_count++; } echo $lang->sprintf($lang->admin_step_insertedviews, $view_count); echo $lang->admin_step_createadmin; } echo $lang->sprintf($lang->admin_step_admintable, $adminuser, $adminemail); $output->print_footer('final'); }
function upgrade12_dbchanges2() { global $db, $output, $mybb; $output->print_header("Performing Queries"); echo "<p>Performing necessary upgrade queries..</p>"; flush(); if ($db->field_exists('recipients', "privatemessages")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "privatemessages DROP recipients;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "privatemessages ADD recipients text NOT NULL AFTER fromid"); if ($db->field_exists('deletetime', "privatemessages")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "privatemessages DROP deletetime;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "privatemessages ADD deletetime bigint(30) NOT NULL default '0' AFTER dateline"); if ($db->field_exists('maxpmrecipients', "usergroups")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "usergroups DROP maxpmrecipients;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "usergroups ADD maxpmrecipients int(4) NOT NULL default '5' AFTER pmquota"); if ($db->field_exists('canwarnusers', "usergroups")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "usergroups DROP canwarnusers;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "usergroups ADD canwarnusers int(1) NOT NULL default '0' AFTER cancustomtitle"); if ($db->field_exists('lastip', "users")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users DROP lastip;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users ADD lastip varchar(50) NOT NULL default '' AFTER regip"); if ($db->field_exists('coppauser', "users")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users DROP coppauser;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users ADD coppauser int(1) NOT NULL default '0'"); if ($db->field_exists('classicpostbit', 'users')) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users DROP classicpostbit;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users ADD classicpostbit int(1) NOT NULL default '0'"); if ($db->field_exists('canreceivewarnings', "usergroups")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "usergroups DROP canreceivewarnings;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "usergroups ADD canreceivewarnings int(1) NOT NULL default '0' AFTER canwarnusers"); if ($db->field_exists('maxwarningsday', "usergroups")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "usergroups DROP maxwarningsday;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "usergroups ADD maxwarningsday int(3) NOT NULL default '3' AFTER canreceivewarnings"); $db->update_query("usergroups", array('canreceivewarnings' => 1), "cancp != 1"); $db->update_query("usergroups", array('maxwarningsday' => 3, 'canwarnusers' => 1), "cancp=1 OR issupermod=1 OR gid=6"); // Admins, Super Mods and Mods if ($db->field_exists('canmodcp', "usergroups")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "usergroups DROP canmodcp;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "usergroups ADD canmodcp int(1) NOT NULL default '0' AFTER maxwarningsday"); $db->update_query("usergroups", array('canmodcp' => 1), "cancp=1 OR issupermod=1 OR gid='6'"); // Admins, Super Mods and Mods if ($db->field_exists('newpms', "users")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users DROP newpms;"); } if ($db->field_exists('keywords', "searchlog")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "searchlog DROP keywords;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "searchlog ADD keywords text NOT NULL AFTER querycache"); if ($db->field_exists('canaddpublicevents', "usergroups") && !$db->field_exists('canaddevents', "usergroups")) { $db->update_query("usergroups", array('canaddpublicevents' => 0), "canaddpublicevents='no'"); $db->update_query("usergroups", array('canaddpublicevents' => 1), "canaddpublicevents='yes'"); $db->write_query("ALTER TABLE " . TABLE_PREFIX . "usergroups CHANGE canaddpublicevents canaddevents int(1) NOT NULL default '0';"); } if ($db->field_exists('canaddprivateevents', "usergroups")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "usergroups DROP canaddprivateevents;"); } if ($db->field_exists('canbypasseventmod', "usergroups")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "usergroups DROP canbypasseventmod;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "usergroups ADD canbypasseventmod int(1) NOT NULL default '0' AFTER canaddevents;"); if ($db->field_exists('canmoderateevents', "usergroups")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "usergroups DROP canmoderateevents;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "usergroups ADD canmoderateevents int(1) NOT NULL default '0' AFTER canbypasseventmod;"); $db->update_query("usergroups", array('canbypasseventmod' => 1, 'canmoderateevents' => 1), "cancp=1 OR issupermod=1"); $db->update_query("usergroups", array('canbypasseventmod' => 0, 'canmoderateevents' => 0), "cancp=0 AND issupermod=0"); $db->update_query("usergroups", array('canaddevents' => 0), "gid='1'"); $db->drop_table("maillogs"); $db->drop_table("mailerrors"); $db->drop_table("promotions"); $db->drop_table("promotionlogs"); $db->drop_table("massemails"); $collation = $db->build_create_table_collation(); $db->write_query("CREATE TABLE " . TABLE_PREFIX . "massemails (\n\t\tmid int unsigned NOT NULL auto_increment,\n\t\tuid int unsigned NOT NULL default '0',\n\t\tsubject varchar(200) NOT NULL default '',\n\t\tmessage text NOT NULL,\n\t\thtmlmessage text NOT NULL,\n\t\ttype tinyint(1) NOT NULL default '0',\n\t\tformat tinyint(1) NOT NULL default '0',\n\t\tdateline bigint(30) NOT NULL default '0',\n\t\tsenddate bigint(30) NOT NULL default '0',\n\t\tstatus tinyint(1) NOT NULL default '0',\n\t\tsentcount int unsigned NOT NULL default '0',\n\t\ttotalcount int unsigned NOT NULL default '0',\n\t\tconditions text NOT NULL,\n\t\tperpage smallint(4) NOT NULL default '50',\n\t\tPRIMARY KEY(mid)\n\t) ENGINE=MyISAM{$collation};"); $db->write_query("CREATE TABLE " . TABLE_PREFIX . "maillogs (\n\t\tmid int unsigned NOT NULL auto_increment,\n\t\tsubject varchar(200) not null default '',\n\t\tmessage TEXT NOT NULL,\n\t\tdateline bigint(30) NOT NULL default '0',\n\t\tfromuid int unsigned NOT NULL default '0',\n\t\tfromemail varchar(200) not null default '',\n\t\ttouid bigint(30) NOT NULL default '0',\n\t\ttoemail varchar(200) NOT NULL default '',\n\t\ttid int unsigned NOT NULL default '0',\n\t\tipaddress varchar(20) NOT NULL default '',\n\t\tPRIMARY KEY(mid)\n\t) ENGINE=MyISAM{$collation};"); $db->write_query("CREATE TABLE " . TABLE_PREFIX . "mailerrors(\n\t\teid int unsigned NOT NULL auto_increment,\n\t\tsubject varchar(200) NOT NULL default '',\n\t\tmessage TEXT NOT NULL,\n\t\ttoaddress varchar(150) NOT NULL default '',\n\t\tfromaddress varchar(150) NOT NULL default '',\n\t\tdateline bigint(30) NOT NULL default '0',\n\t\terror text NOT NULL,\n\t\tsmtperror varchar(200) NOT NULL default '',\n\t\tsmtpcode int(5) NOT NULL default '0',\n\t\tPRIMARY KEY(eid)\n \t) ENGINE=MyISAM{$collation};"); $db->write_query("CREATE TABLE " . TABLE_PREFIX . "promotions (\n\t\tpid int unsigned NOT NULL auto_increment,\n\t\ttitle varchar(120) NOT NULL default '',\n\t\tdescription text NOT NULL,\n\t\tenabled tinyint(1) NOT NULL default '1',\n\t\tlogging tinyint(1) NOT NULL default '0',\n\t\tposts int NOT NULL default '0',\n\t\tposttype char(2) NOT NULL default '',\n\t\tregistered int NOT NULL default '0',\n\t\tregisteredtype varchar(20) NOT NULL default '',\n\t\treputations int NOT NULL default '0',\n\t\treputationtype char(2) NOT NULL default '',\n\t\trequirements varchar(200) NOT NULL default '',\n\t\toriginalusergroup varchar(120) NOT NULL default '0',\n\t\tnewusergroup smallint unsigned NOT NULL default '0',\n\t\tusergrouptype varchar(120) NOT NULL default '0',\n\t\tPRIMARY KEY (pid)\n\t) ENGINE=MyISAM{$collation};"); $db->write_query("CREATE TABLE " . TABLE_PREFIX . "promotionlogs(\n\t\tplid int unsigned NOT NULL auto_increment,\n\t\tpid int unsigned NOT NULL default '0',\n\t\tuid int unsigned NOT NULL default '0',\n\t\toldusergroup varchar(200) NOT NULL default '0',\n\t\tnewusergroup smallint unsigned NOT NULL default '0',\n\t\tdateline bigint(30) NOT NULL default '0',\n\t\ttype varchar(9) NOT NULL default 'primary',\n\t\tPRIMARY KEY(plid)\n \t) ENGINE=MyISAM{$collation};"); if ($db->field_exists('maxemails', "usergroups")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "usergroups DROP maxemails;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "usergroups ADD maxemails int(3) NOT NULL default '5' AFTER cansendemail"); if ($db->field_exists('parseorder', "mycode")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "mycode DROP parseorder;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "mycode ADD parseorder smallint unsigned NOT NULL default '0' AFTER active"); if ($db->field_exists('mod_edit_posts', "forums")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "forums DROP mod_edit_posts;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "forums ADD mod_edit_posts int(1) NOT NULL default '0' AFTER modthreads"); if ($db->field_exists('pmpopup', "users") && !$db->field_exists('pmnotice', "users")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users CHANGE pmpopup pmnotice int(1) NOT NULL default '0'"); } $db->drop_table("tasks"); $db->drop_table("tasklog"); $db->write_query("CREATE TABLE " . TABLE_PREFIX . "tasks (\n\t\ttid int unsigned NOT NULL auto_increment,\n\t\ttitle varchar(120) NOT NULL default '',\n\t\tdescription text NOT NULL,\n\t\tfile varchar(30) NOT NULL default '',\n\t\tminute varchar(200) NOT NULL default '',\n\t\thour varchar(200) NOT NULL default '',\n\t\tday varchar(100) NOT NULL default '',\n\t\tmonth varchar(30) NOT NULL default '',\n\t\tweekday varchar(15) NOT NULL default '',\n\t\tnextrun bigint(30) NOT NULL default '0',\n\t\tlastrun bigint(30) NOT NULL default '0',\n\t\tenabled int(1) NOT NULL default '1',\n\t\tlogging int(1) NOT NULL default '0',\n\t\tlocked bigint(30) NOT NULL default '0',\n\t\tPRIMARY KEY(tid)\n\t) ENGINE=MyISAM{$collation};"); $db->write_query("CREATE TABLE " . TABLE_PREFIX . "tasklog (\n\t\tlid int unsigned NOT NULL auto_increment,\n\t\ttid int unsigned NOT NULL default '0',\n\t\tdateline bigint(30) NOT NULL default '0',\n\t\tdata text NOT NULL,\n\t\tPRIMARY KEY(lid)\n\t) ENGINE=MyISAM{$collation};"); include_once MYBB_ROOT . "inc/functions_task.php"; $tasks = file_get_contents(INSTALL_ROOT . 'resources/tasks.xml'); $parser = new XMLParser($tasks); $parser->collapse_dups = 0; $tree = $parser->get_tree(); // Insert scheduled tasks foreach ($tree['tasks'][0]['task'] as $task) { $new_task = array('title' => $db->escape_string($task['title'][0]['value']), 'description' => $db->escape_string($task['description'][0]['value']), 'file' => $db->escape_string($task['file'][0]['value']), 'minute' => $db->escape_string($task['minute'][0]['value']), 'hour' => $db->escape_string($task['hour'][0]['value']), 'day' => $db->escape_string($task['day'][0]['value']), 'weekday' => $db->escape_string($task['weekday'][0]['value']), 'month' => $db->escape_string($task['month'][0]['value']), 'enabled' => $db->escape_string($task['enabled'][0]['value']), 'logging' => $db->escape_string($task['logging'][0]['value'])); $new_task['nextrun'] = fetch_next_run($new_task); $db->insert_query("tasks", $new_task); $taskcount++; } if ($db->table_exists("favorites") && !$db->table_exists("threadsubscriptions")) { $db->write_query("RENAME TABLE " . TABLE_PREFIX . "favorites TO " . TABLE_PREFIX . "threadsubscriptions"); } if ($db->field_exists('fid', "threadsubscriptions")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "threadsubscriptions CHANGE fid sid int unsigned NOT NULL auto_increment"); } if ($db->field_exists('type', "threadsubscriptions")) { $db->update_query("threadsubscriptions", array('type' => 0), "type='f'"); $db->update_query("threadsubscriptions", array('type' => 1), "type='s'"); $db->write_query("ALTER TABLE " . TABLE_PREFIX . "threadsubscriptions CHANGE type notification int(1) NOT NULL default '0'"); } if ($db->field_exists('dateline', "threadsubscriptions")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "threadsubscriptions DROP dateline;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "threadsubscriptions ADD dateline bigint(30) NOT NULL default '0'"); if ($db->field_exists('subscriptionkey', "threadsubscriptions")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "threadsubscriptions DROP subscriptionkey;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "threadsubscriptions ADD subscriptionkey varchar(32) NOT NULL default ''"); if ($db->field_exists('emailnotify', "users")) { $db->update_query("users", array('emailnotify' => 0), "emailnotify='no' OR emailnotify='0'"); $db->update_query("users", array('emailnotify' => 2), "emailnotify='yes' OR emailnotify='1'"); $db->update_query("users", array('emailnotify' => 0), "emailnotify != 1 AND emailnotify != 2"); $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users CHANGE emailnotify subscriptionmethod int(1) NOT NULL default '0'"); } $db->drop_table("warninglevels"); $db->drop_table("warningtypes"); $db->drop_table("warnings"); $db->write_query("CREATE TABLE " . TABLE_PREFIX . "warninglevels (\n\t\tlid int unsigned NOT NULL auto_increment,\n\t\tpercentage int(3) NOT NULL default '0',\n\t\taction text NOT NULL,\n\t\tPRIMARY KEY(lid)\n\t) ENGINE=MyISAM{$collation};"); $db->write_query("CREATE TABLE " . TABLE_PREFIX . "warningtypes (\n\t\ttid int unsigned NOT NULL auto_increment,\n\t\ttitle varchar(120) NOT NULL default '',\n\t\tpoints int unsigned NOT NULL default '0',\n\t\texpirationtime bigint(30) NOT NULL default '0',\n\t\tPRIMARY KEY(tid)\n\t) ENGINE=MyISAM{$collation};"); $db->write_query("CREATE TABLE " . TABLE_PREFIX . "warnings (\n\t\twid int unsigned NOT NULL auto_increment,\n\t\tuid int unsigned NOT NULL default '0',\n\t\ttid int unsigned NOT NULL default '0',\n\t\tpid int unsigned NOT NULL default '0',\n\t\ttitle varchar(120) NOT NULL default '',\n\t\tpoints int unsigned NOT NULL default '0',\n\t\tdateline bigint(30) NOT NULL default '0',\n\t\tissuedby int unsigned NOT NULL default '0',\n\t\texpires bigint(30) NOT NULL default '0',\n\t\texpired int(1) NOT NULL default '0',\n\t\tdaterevoked bigint(30) NOT NULL default '0',\n\t\trevokedby int unsigned NOT NULL default '0',\n\t\trevokereason text NOT NULL,\n\t\tnotes text NOT NULL,\n\t\tPRIMARY KEY(wid)\n\t) ENGINE=MyISAM{$collation};"); if ($db->field_exists('warningpoints', "users")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users DROP warningpoints;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users ADD warningpoints int(3) NOT NULL default '0' AFTER unreadpms"); if ($db->field_exists('moderateposts', "users")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users DROP moderateposts;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users ADD moderateposts int(1) NOT NULL default '0' AFTER warningpoints"); if ($db->field_exists('moderationtime', "users")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users DROP moderationtime;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users ADD moderationtime bigint(30) NOT NULL default '0' AFTER moderateposts"); if ($db->field_exists('suspendposting', "users")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users DROP suspendposting;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users ADD suspendposting int(1) NOT NULL default '0' AFTER moderationtime"); if ($db->field_exists('suspensiontime', "users")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users DROP suspensiontime;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users ADD suspensiontime bigint(30) NOT NULL default '0' AFTER suspendposting"); $db->write_query("ALTER TABLE " . TABLE_PREFIX . "banned CHANGE oldadditionalgroups oldadditionalgroups TEXT NOT NULL"); if ($db->field_exists('birthdayprivacy', "users")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users DROP birthdayprivacy;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users ADD birthdayprivacy varchar(4) NOT NULL default 'all' AFTER birthday"); if ($db->field_exists('birthdayprivacy', "users")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users DROP birthdayprivacy;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users ADD birthdayprivacy varchar(4) NOT NULL default 'all' AFTER birthday"); if ($db->field_exists('longregip', "users")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users DROP longregip;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users ADD longregip int(11) NOT NULL default '0' AFTER lastip"); if ($db->field_exists('longlastip', "users")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users DROP longlastip;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users ADD longlastip int(11) NOT NULL default '0' AFTER lastip"); // Unused column if ($db->field_exists('titles', "searchlog")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "searchlog DROP titles;"); } $db->drop_table("adminlog"); $db->write_query("CREATE TABLE " . TABLE_PREFIX . "adminlog (\n\t uid int unsigned NOT NULL default '0',\n\t ipaddress varchar(50) NOT NULL default '',\n\t dateline bigint(30) NOT NULL default '0',\n\t module varchar(50) NOT NULL default '',\n\t action varchar(50) NOT NULL default '',\n\t data text NOT NULL,\n\t KEY module (module, action)\n\t) ENGINE=MyISAM{$collation};"); if ($db->field_exists('data', "adminsessions")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "adminsessions DROP data;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "adminsessions ADD data TEXT NOT NULL AFTER lastactive;"); if ($db->field_exists('isdefault', "settings")) { $db->write_query("ALTER TABLE " . TABLE_PREFIX . "settings DROP isdefault;"); } $db->write_query("ALTER TABLE " . TABLE_PREFIX . "settings ADD isdefault int(1) NOT NULL default '0' AFTER gid;"); $setting_group_cache = array(); $query = $db->simple_select("settinggroups", "gid, isdefault"); while ($settinggroup = $db->fetch_array($query)) { $setting_group_cache[$settinggroup['gid']] = $settinggroup['isdefault']; } $query = $db->simple_select("settings", "gid, sid"); while ($setting = $db->fetch_array($query)) { if ($setting_group_cache[$setting['gid']] == 1) { $db->update_query("settings", array('isdefault' => 1), "sid = '{$setting['sid']}'", 1); } } $db->update_query("settings", array('value' => 'classic'), "name='postlayout' AND value != 'horizontal'"); $db->update_query("settings", array('optionscode' => $db->escape_string('php <select name=\\"upsetting[{$setting[\'name\']}]\\"><option value=\\"standard\\">".($lang->setting_searchtype_standard?$lang->setting_searchtype_standard:"Standard")."</option>".($db->supports_fulltext("threads") && $db->supports_fulltext_boolean("posts")?"<option value=\\"fulltext\\"".($setting[\'value\']=="fulltext"?" selected=\\"selected\\"":"").">".($lang->setting_searchtype_fulltext?$lang->setting_searchtype_fulltext:"Full Text")."</option>":"")."</select>')), "name='searchtype'", 1); $contents = "Done</p>"; $contents .= "<p>Click next to continue with the upgrade process.</p>"; $output->print_contents($contents); global $footer_extra; $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = \$\$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>"; $output->print_footer("12_dbchanges3"); }
function sync_tasks($redo = 0) { global $db; $taskcount = 0; $tasks = array(); if ($redo == 2) { $db->drop_table("tasks"); switch ($db->type) { case "pgsql": $db->write_query("CREATE TABLE " . TABLE_PREFIX . "tasks (\n\t\t\t\t\ttid serial,\n\t\t\t\t\ttitle varchar(120) NOT NULL default '',\n\t\t\t\t\tdescription text NOT NULL default '',\n\t\t\t\t\tfile varchar(30) NOT NULL default '',\n\t\t\t\t\tminute varchar(200) NOT NULL default '',\n\t\t\t\t\thour varchar(200) NOT NULL default '',\n\t\t\t\t\tday varchar(100) NOT NULL default '',\n\t\t\t\t\tmonth varchar(30) NOT NULL default '',\n\t\t\t\t\tweekday varchar(15) NOT NULL default '',\n\t\t\t\t\tnextrun bigint NOT NULL default '0',\n\t\t\t\t\tlastrun bigint NOT NULL default '0',\n\t\t\t\t\tenabled int NOT NULL default '1',\n\t\t\t\t\tlogging int NOT NULL default '0',\n\t\t\t\t\tlocked bigint NOT NULL default '0',\n\t\t\t\t\tPRIMARY KEY(tid)\n\t\t\t\t);"); break; case "sqlite": $db->write_query("CREATE TABLE " . TABLE_PREFIX . "tasks (\n\t\t\t\t\ttid INTEGER PRIMARY KEY,\n\t\t\t\t\ttitle varchar(120) NOT NULL default '',\n\t\t\t\t\tdescription TEXT NOT NULL,\n\t\t\t\t\tfile varchar(30) NOT NULL default '',\n\t\t\t\t\tminute varchar(200) NOT NULL default '',\n\t\t\t\t\thour varchar(200) NOT NULL default '',\n\t\t\t\t\tday varchar(100) NOT NULL default '',\n\t\t\t\t\tmonth varchar(30) NOT NULL default '',\n\t\t\t\t\tweekday varchar(15) NOT NULL default '',\n\t\t\t\t\tnextrun bigint(30) NOT NULL default '0',\n\t\t\t\t\tlastrun bigint(30) NOT NULL default '0',\n\t\t\t\t\tenabled int(1) NOT NULL default '1',\n\t\t\t\t\tlogging int(1) NOT NULL default '0',\n\t\t\t\t\tlocked bigint(30) NOT NULL default '0'\n\t\t\t\t);"); break; case "mysql": default: $db->write_query("CREATE TABLE " . TABLE_PREFIX . "tasks (\n\t\t\t\t\ttid int unsigned NOT NULL auto_increment,\n\t\t\t\t\ttitle varchar(120) NOT NULL default '',\n\t\t\t\t\tdescription text NOT NULL,\n\t\t\t\t\tfile varchar(30) NOT NULL default '',\n\t\t\t\t\tminute varchar(200) NOT NULL default '',\n\t\t\t\t\thour varchar(200) NOT NULL default '',\n\t\t\t\t\tday varchar(100) NOT NULL default '',\n\t\t\t\t\tmonth varchar(30) NOT NULL default '',\n\t\t\t\t\tweekday varchar(15) NOT NULL default '',\n\t\t\t\t\tnextrun bigint(30) NOT NULL default '0',\n\t\t\t\t\tlastrun bigint(30) NOT NULL default '0',\n\t\t\t\t\tenabled int(1) NOT NULL default '1',\n\t\t\t\t\tlogging int(1) NOT NULL default '0',\n\t\t\t\t\tlocked bigint(30) NOT NULL default '0',\n\t\t\t\t\tPRIMARY KEY (tid)\n\t\t\t\t) ENGINE=MyISAM;"); } } else { $query = $db->simple_select("tasks", "file,tid"); while ($task = $db->fetch_array($query)) { $tasks[$task['file']] = $task['tid']; } } require_once MYBB_ROOT . "inc/functions_task.php"; $task_file = file_get_contents(INSTALL_ROOT . 'resources/tasks.xml'); $parser = new XMLParser($task_file); $parser->collapse_dups = 0; $tree = $parser->get_tree(); // Resync tasks foreach ($tree['tasks'][0]['task'] as $task) { if (!$tasks[$task['file'][0]['value']] || $redo == 2) { $new_task = array('title' => $db->escape_string($task['title'][0]['value']), 'description' => $db->escape_string($task['description'][0]['value']), 'file' => $db->escape_string($task['file'][0]['value']), 'minute' => $db->escape_string($task['minute'][0]['value']), 'hour' => $db->escape_string($task['hour'][0]['value']), 'day' => $db->escape_string($task['day'][0]['value']), 'weekday' => $db->escape_string($task['weekday'][0]['value']), 'month' => $db->escape_string($task['month'][0]['value']), 'enabled' => $db->escape_string($task['enabled'][0]['value']), 'logging' => $db->escape_string($task['logging'][0]['value'])); $new_task['nextrun'] = fetch_next_run($new_task); $db->insert_query("tasks", $new_task); $taskcount++; } else { $update_task = array('title' => $db->escape_string($task['title'][0]['value']), 'description' => $db->escape_string($task['description'][0]['value']), 'file' => $db->escape_string($task['file'][0]['value'])); $db->update_query("tasks", $update_task, "file='" . $db->escape_string($task['file'][0]['value']) . "'"); } } return $taskcount; }
/** * Add a task. * * Code stolen from MyBB itself. */ function captchapack_task_add($task) { require_once MYBB_ROOT . 'inc/functions_task.php'; global $db, $cache; // Merge default values $task_def = array('title' => '', 'description' => '', 'file' => '', 'minute' => '*', 'hour' => '*', 'day' => '*', 'month' => '*', 'weekday' => '*', 'enabled' => 0, 'logging' => 1); $task = array_merge($task_def, $task); if (!$task['file'] || !$task['title']) { return false; } // If there's a task with the same title or filename, drop it captchapack_task_drop($task['file'], $task['title']); // Escape all the things in the task $task = array('title' => $db->escape_string($task['title']), 'description' => $db->escape_string($task['description']), 'file' => $db->escape_string($task['file']), 'minute' => $db->escape_string($task['minute']), 'hour' => $db->escape_string($task['hour']), 'day' => $db->escape_string($task['day']), 'month' => $db->escape_string($task['month']), 'weekday' => $db->escape_string($task['weekday']), 'enabled' => (int) $task['enabled'], 'logging' => (int) $task['logging']); // Fill nextrun $task['nextrun'] = fetch_next_run($task); // Insert, and update cache $db->insert_query("tasks", $task); $cache->update_tasks(); return true; }
function mysupport_insert_task() { global $db, $lang; $lang->load("mysupport"); include_once MYBB_ROOT . "inc/functions_task.php"; $new_task = array("title" => $lang->mysupport, "description" => $lang->mysupport_task_description, "file" => "mysupport", "minute" => 0, "hour" => 0, "day" => "*", "month" => "*", "weekday" => "*", "enabled" => 1, "logging" => 1); $new_task['nextrun'] = fetch_next_run($new_task); $db->insert_query("tasks", $new_task); }
function myalerts_activate() { global $db, $lang, $PL, $plugins, $cache; if (!isset($lang->myalerts)) { $lang->load('myalerts'); } if (!file_exists(PLUGINLIBRARY)) { flash_message($lang->myalerts_pluginlibrary_missing, 'error'); admin_redirect('index.php?module=config-plugins'); } $PL or (require_once PLUGINLIBRARY); if ($PL->version < 9) { flash_message('This plugin requires PluginLibrary 9 or newer', 'error'); admin_redirect('index.php?module=config-plugins'); } $plugin_info = myalerts_info(); $euantorPlugins = $cache->read('euantor_plugins'); if (!empty($euantorPlugins) && isset($euantorPlugins['myalerts'])) { $oldVersion = $euantorPlugins['myalerts']; if ($oldVersion['version'] == '1.05') { myalerts_upgrade_105_200(); } } $euantorPlugins['myalerts'] = array('title' => 'MyAlerts', 'version' => $plugin_info['version']); $cache->update('euantor_plugins', $euantorPlugins); $PL->settings('myalerts', $lang->setting_group_myalerts, $lang->setting_group_myalerts_desc, array('perpage' => array('title' => $lang->setting_myalerts_perpage, 'description' => $lang->setting_myalerts_perpage_desc, 'value' => '10', 'optionscode' => 'text'), 'dropdown_limit' => array('title' => $lang->setting_myalerts_dropdown_limit, 'description' => $lang->setting_myalerts_dropdown_limit_desc, 'value' => '5', 'optionscode' => 'text'), 'autorefresh' => array('title' => $lang->setting_myalerts_autorefresh, 'description' => $lang->setting_myalerts_autorefresh_desc, 'value' => '0', 'optionscode' => 'text'), 'avatar_size' => array('title' => $lang->setting_myalerts_avatar_size, 'description' => $lang->setting_myalerts_avatar_size_desc, 'optionscode' => 'text', 'value' => '64|64'))); $dir = new DirectoryIterator(MYALERTS_PLUGIN_PATH . '/templates'); $templates = array(); foreach ($dir as $file) { if (!$file->isDot() && !$file->isDir() && pathinfo($file->getPathname(), PATHINFO_EXTENSION) === 'html') { $templateName = $file->getPathname(); $templateName = basename($templateName, '.html'); $templates[$templateName] = file_get_contents($file->getPathname()); } } $PL->templates('myalerts', 'MyAlerts', $templates); $stylesheet = file_get_contents(MYALERTS_PLUGIN_PATH . '/stylesheets/alerts.css'); $PL->stylesheet('alerts.css', $stylesheet); // Attach usercp.css to alerts.php $query = $db->simple_select('themestylesheets', 'sid,attachedto,tid', "name = 'usercp.css'"); while ($userCpStylesheet = $db->fetch_array($query)) { $sid = (int) $userCpStylesheet['sid']; $db->update_query('themestylesheets', array('attachedto' => $db->escape_string($userCpStylesheet['attachedto'] . '|alerts.php')), "sid = {$sid}"); update_theme_stylesheet_list((int) $userCpStylesheet['tid']); } require_once MYBB_ROOT . '/inc/adminfunctions_templates.php'; find_replace_templatesets('headerinclude', '/$/', '{$myalerts_js}'); find_replace_templatesets('header_welcomeblock_member', "#" . preg_quote('{$modcplink}') . "#i", '{$myalerts_headericon}{$modcplink}'); find_replace_templatesets('footer', '/$/', '{$myalerts_modal}'); $taskExists = $db->simple_select('tasks', 'tid', 'file = \'myalerts\'', array('limit' => '1')); if ($db->num_rows($taskExists) == 0) { require_once MYBB_ROOT . '/inc/functions_task.php'; $myTask = array('title' => $lang->myalerts_task_title, 'file' => 'myalerts', 'description' => $lang->myalerts_task_description, 'minute' => 0, 'hour' => 1, 'day' => '*', 'weekday' => 1, 'month' => '*', 'nextrun' => TIME_NOW + 3600, 'lastrun' => 0, 'enabled' => 1, 'logging' => 1, 'locked' => 0); $task_id = $db->insert_query('tasks', $myTask); $theTask = $db->fetch_array($db->simple_select('tasks', '*', 'tid = ' . (int) $task_id, 1)); $nextrun = fetch_next_run($theTask); $db->update_query('tasks', 'nextrun = ' . $nextrun, 'tid = ' . (int) $task_id); $plugins->run_hooks('admin_tools_tasks_add_commit'); $cache->update_tasks(); } else { require_once MYBB_ROOT . '/inc/functions_task.php'; $theTask = $db->fetch_array($db->simple_select('tasks', '*', 'file = \'myalerts\'', 1)); $db->update_query('tasks', array('enabled' => 1, 'nextrun' => fetch_next_run($theTask)), 'file = \'myalerts\''); $cache->update_tasks(); } $plugins->run_hooks('myalerts_activate'); }