inital commit
This commit is contained in:
147
webroot/forum/inc/tasks/backupdb.php
Normal file
147
webroot/forum/inc/tasks/backupdb.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
/**
|
||||
* MyBB 1.8
|
||||
* Copyright 2014 MyBB Group, All Rights Reserved
|
||||
*
|
||||
* Website: http://www.mybb.com
|
||||
* License: http://www.mybb.com/about/license
|
||||
*
|
||||
*/
|
||||
|
||||
function task_backupdb($task)
|
||||
{
|
||||
global $db, $config, $lang, $plugins;
|
||||
static $contents;
|
||||
|
||||
@set_time_limit(0);
|
||||
|
||||
if(!defined('MYBB_ADMIN_DIR'))
|
||||
{
|
||||
if(!isset($config['admin_dir']))
|
||||
{
|
||||
$config['admin_dir'] = "admin";
|
||||
}
|
||||
|
||||
define('MYBB_ADMIN_DIR', MYBB_ROOT.$config['admin_dir'].'/');
|
||||
}
|
||||
|
||||
// Check if folder is writable, before allowing submission
|
||||
if(!is_writable(MYBB_ADMIN_DIR."/backups"))
|
||||
{
|
||||
add_task_log($task, $lang->task_backup_cannot_write_backup);
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->set_table_prefix('');
|
||||
|
||||
$file = MYBB_ADMIN_DIR.'backups/backup_'.date("_Ymd_His_").random_str(16);
|
||||
|
||||
if(function_exists('gzopen'))
|
||||
{
|
||||
$fp = gzopen($file.'.incomplete.sql.gz', 'w9');
|
||||
}
|
||||
else
|
||||
{
|
||||
$fp = fopen($file.'.incomplete.sql', 'w');
|
||||
}
|
||||
|
||||
$tables = $db->list_tables($config['database']['database'], $config['database']['table_prefix']);
|
||||
|
||||
$time = date('dS F Y \a\t H:i', TIME_NOW);
|
||||
$contents = "-- MyBB Database Backup\n-- Generated: {$time}\n-- -------------------------------------\n\n";
|
||||
|
||||
if(is_object($plugins))
|
||||
{
|
||||
$args = array(
|
||||
'task' => &$task,
|
||||
'tables' => &$tables,
|
||||
);
|
||||
$plugins->run_hooks('task_backupdb', $args);
|
||||
}
|
||||
|
||||
foreach($tables as $table)
|
||||
{
|
||||
$field_list = array();
|
||||
$fields_array = $db->show_fields_from($table);
|
||||
foreach($fields_array as $field)
|
||||
{
|
||||
$field_list[] = $field['Field'];
|
||||
}
|
||||
|
||||
$fields = "`".implode("`,`", $field_list)."`";
|
||||
|
||||
$structure = $db->show_create_table($table).";\n";
|
||||
$contents .= $structure;
|
||||
clear_overflow($fp, $contents);
|
||||
|
||||
if($db->engine == 'mysqli')
|
||||
{
|
||||
$query = mysqli_query($db->read_link, "SELECT * FROM {$db->table_prefix}{$table}", MYSQLI_USE_RESULT);
|
||||
}
|
||||
else
|
||||
{
|
||||
$query = $db->simple_select($table);
|
||||
}
|
||||
|
||||
while($row = $db->fetch_array($query))
|
||||
{
|
||||
$insert = "INSERT INTO {$table} ($fields) VALUES (";
|
||||
$comma = '';
|
||||
foreach($field_list as $field)
|
||||
{
|
||||
if(!isset($row[$field]) || is_null($row[$field]))
|
||||
{
|
||||
$insert .= $comma."NULL";
|
||||
}
|
||||
else if($db->engine == 'mysqli')
|
||||
{
|
||||
$insert .= $comma."'".mysqli_real_escape_string($db->read_link, $row[$field])."'";
|
||||
}
|
||||
else
|
||||
{
|
||||
$insert .= $comma."'".$db->escape_string($row[$field])."'";
|
||||
}
|
||||
$comma = ',';
|
||||
}
|
||||
$insert .= ");\n";
|
||||
$contents .= $insert;
|
||||
clear_overflow($fp, $contents);
|
||||
}
|
||||
$db->free_result($query);
|
||||
}
|
||||
|
||||
$db->set_table_prefix(TABLE_PREFIX);
|
||||
|
||||
if(function_exists('gzopen'))
|
||||
{
|
||||
gzwrite($fp, $contents);
|
||||
gzclose($fp);
|
||||
rename($file.'.incomplete.sql.gz', $file.'.sql.gz');
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite($fp, $contents);
|
||||
fclose($fp);
|
||||
rename($file.'.incomplete.sql', $file.'.sql');
|
||||
}
|
||||
|
||||
add_task_log($task, $lang->task_backup_ran);
|
||||
}
|
||||
}
|
||||
|
||||
// Allows us to refresh cache to prevent over flowing
|
||||
function clear_overflow($fp, &$contents)
|
||||
{
|
||||
global $mybb;
|
||||
|
||||
if(function_exists('gzopen'))
|
||||
{
|
||||
gzwrite($fp, $contents);
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite($fp, $contents);
|
||||
}
|
||||
|
||||
$contents = '';
|
||||
}
|
||||
88
webroot/forum/inc/tasks/checktables.php
Normal file
88
webroot/forum/inc/tasks/checktables.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* MyBB 1.8
|
||||
* Copyright 2014 MyBB Group, All Rights Reserved
|
||||
*
|
||||
* Website: http://www.mybb.com
|
||||
* License: http://www.mybb.com/about/license
|
||||
*
|
||||
*/
|
||||
|
||||
function task_checktables($task)
|
||||
{
|
||||
global $db, $mybb, $lang, $plugins;
|
||||
|
||||
// Sorry SQLite, you don't have a decent way of checking if the table is corrupted or not.
|
||||
if($db->type == "sqlite")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@set_time_limit(0);
|
||||
|
||||
$ok = array(
|
||||
"The storage engine for the table doesn't support check",
|
||||
"Table is already up to date",
|
||||
"OK"
|
||||
);
|
||||
|
||||
$comma = "";
|
||||
$tables_list = "";
|
||||
$repaired = "";
|
||||
$setting_done = false;
|
||||
|
||||
$tables = $db->list_tables($mybb->config['database']['database'], $mybb->config['database']['table_prefix']);
|
||||
foreach($tables as $key => $table)
|
||||
{
|
||||
$tables_list .= "{$comma}{$table} ";
|
||||
$comma = ",";
|
||||
}
|
||||
|
||||
if($tables_list)
|
||||
{
|
||||
$query = $db->query("CHECK TABLE {$tables_list}CHANGED;");
|
||||
while($table = $db->fetch_array($query))
|
||||
{
|
||||
if(!in_array($table['Msg_text'], $ok))
|
||||
{
|
||||
if($table['Table'] != $mybb->config['database']['database'].".".TABLE_PREFIX."settings" && $setting_done != true)
|
||||
{
|
||||
$boardclosed = $mybb->settings['boardclosed'];
|
||||
$boardclosed_reason = $mybb->settings['boardclosed_reason'];
|
||||
|
||||
$db->update_query("settings", array('value' => 1), "name='boardclosed'", 1);
|
||||
$db->update_query("settings", array('value' => $db->escape_string($lang->error_database_repair)), "name='boardclosed_reason'", 1);
|
||||
rebuild_settings();
|
||||
|
||||
$setting_done = true;
|
||||
}
|
||||
|
||||
$db->query("REPAIR TABLE {$table['Table']}");
|
||||
$repaired[] = $table['Table'];
|
||||
}
|
||||
}
|
||||
|
||||
if($setting_done == true)
|
||||
{
|
||||
$db->update_query("settings", array('value' => (int)$boardclosed), "name='boardclosed'", 1);
|
||||
$db->update_query("settings", array('value' => $db->escape_string($boardclosed_reason)), "name='boardclosed_reason'", 1);
|
||||
|
||||
rebuild_settings();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(is_object($plugins))
|
||||
{
|
||||
$plugins->run_hooks('task_checktables', $task);
|
||||
}
|
||||
|
||||
if(!empty($repaired))
|
||||
{
|
||||
add_task_log($task, $lang->sprintf($lang->task_checktables_ran_found, implode(', ', $repaired)));
|
||||
}
|
||||
else
|
||||
{
|
||||
add_task_log($task, $lang->task_checktables_ran);
|
||||
}
|
||||
}
|
||||
92
webroot/forum/inc/tasks/dailycleanup.php
Normal file
92
webroot/forum/inc/tasks/dailycleanup.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* MyBB 1.8
|
||||
* Copyright 2014 MyBB Group, All Rights Reserved
|
||||
*
|
||||
* Website: http://www.mybb.com
|
||||
* License: http://www.mybb.com/about/license
|
||||
*
|
||||
*/
|
||||
|
||||
function task_dailycleanup($task)
|
||||
{
|
||||
global $mybb, $db, $cache, $lang, $plugins;
|
||||
|
||||
require_once MYBB_ROOT."inc/functions_user.php";
|
||||
|
||||
$time = array(
|
||||
'sessionstime' => TIME_NOW-60*60*24,
|
||||
'threadreadcut' => TIME_NOW-(((int)$mybb->settings['threadreadcut'])*60*60*24),
|
||||
'privatemessages' => TIME_NOW-(60*60*24*7),
|
||||
'deleteinvite' => TIME_NOW-(((int)$mybb->settings['deleteinvites'])*60*60*24),
|
||||
'stoppmtracking' => TIME_NOW-(60*60*24*180)
|
||||
);
|
||||
|
||||
if(is_object($plugins))
|
||||
{
|
||||
$args = array(
|
||||
'task' => &$task,
|
||||
'time' => &$time
|
||||
);
|
||||
$plugins->run_hooks('task_dailycleanup_start', $args);
|
||||
}
|
||||
|
||||
// Clear out sessions older than 24h
|
||||
$db->delete_query("sessions", "time < '".(int)$time['sessionstime']."'");
|
||||
|
||||
// Delete old read topics
|
||||
if($mybb->settings['threadreadcut'] > 0)
|
||||
{
|
||||
$db->delete_query("threadsread", "dateline < '".(int)$time['threadreadcut']."'");
|
||||
$db->delete_query("forumsread", "dateline < '".(int)$time['threadreadcut']."'");
|
||||
}
|
||||
|
||||
// Check PMs moved to trash over a week ago & delete them
|
||||
$query = $db->simple_select("privatemessages", "pmid, uid, folder", "deletetime<='".(int)$time['privatemessages']."' AND folder='4'");
|
||||
while($pm = $db->fetch_array($query))
|
||||
{
|
||||
$user_update[$pm['uid']] = 1;
|
||||
$pm_update[] = $pm['pmid'];
|
||||
}
|
||||
|
||||
// Delete old group invites
|
||||
if($mybb->settings['deleteinvites'] > 0)
|
||||
{
|
||||
$db->delete_query("joinrequests", "dateline < '".(int)$time['deleteinvite']."' AND invite='1'");
|
||||
}
|
||||
|
||||
// Stop tracking read PMs after 6 months
|
||||
$sql_array = array(
|
||||
"receipt" => 0
|
||||
);
|
||||
$db->update_query("privatemessages", $sql_array, "receipt='2' AND folder!='3' AND status!='0' AND readtime < '".(int)$time['stoppmtracking']."'");
|
||||
|
||||
if(is_object($plugins))
|
||||
{
|
||||
$args = array(
|
||||
'user_update' => &$user_update,
|
||||
'pm_update' => &$pm_update
|
||||
);
|
||||
$plugins->run_hooks('task_dailycleanup_end', $args);
|
||||
}
|
||||
|
||||
if(!empty($pm_update))
|
||||
{
|
||||
$db->delete_query("privatemessages", "pmid IN(".implode(',', $pm_update).")");
|
||||
}
|
||||
|
||||
if(!empty($user_update))
|
||||
{
|
||||
foreach($user_update as $uid => $data)
|
||||
{
|
||||
update_pm_count($uid);
|
||||
}
|
||||
}
|
||||
|
||||
$cache->update_most_replied_threads();
|
||||
$cache->update_most_viewed_threads();
|
||||
$cache->update_birthdays();
|
||||
$cache->update_forumsdisplay();
|
||||
|
||||
add_task_log($task, $lang->task_dailycleanup_ran);
|
||||
}
|
||||
259
webroot/forum/inc/tasks/delayedmoderation.php
Normal file
259
webroot/forum/inc/tasks/delayedmoderation.php
Normal file
@@ -0,0 +1,259 @@
|
||||
<?php
|
||||
/**
|
||||
* MyBB 1.8
|
||||
* Copyright 2014 MyBB Group, All Rights Reserved
|
||||
*
|
||||
* Website: http://www.mybb.com
|
||||
* License: http://www.mybb.com/about/license
|
||||
*
|
||||
*/
|
||||
|
||||
function task_delayedmoderation($task)
|
||||
{
|
||||
global $db, $lang, $plugins;
|
||||
|
||||
require_once MYBB_ROOT."inc/class_moderation.php";
|
||||
$moderation = new Moderation;
|
||||
|
||||
require_once MYBB_ROOT."inc/class_custommoderation.php";
|
||||
$custommod = new CustomModeration;
|
||||
|
||||
// Iterate through all our delayed moderation actions
|
||||
$query = $db->simple_select("delayedmoderation", "*", "delaydateline <= '".TIME_NOW."'");
|
||||
while($delayedmoderation = $db->fetch_array($query))
|
||||
{
|
||||
if(is_object($plugins))
|
||||
{
|
||||
$args = array(
|
||||
'task' => &$task,
|
||||
'delayedmoderation' => &$delayedmoderation,
|
||||
);
|
||||
$plugins->run_hooks('task_delayedmoderation', $args);
|
||||
}
|
||||
|
||||
$tids = explode(',', $delayedmoderation['tids']);
|
||||
$input = my_unserialize($delayedmoderation['inputs']);
|
||||
|
||||
if(my_strpos($delayedmoderation['type'], "modtool") !== false)
|
||||
{
|
||||
list(, $custom_id) = explode('_', $delayedmoderation['type'], 2);
|
||||
$custommod->execute($custom_id, $tids);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch($delayedmoderation['type'])
|
||||
{
|
||||
case "openclosethread":
|
||||
$closed_tids = $open_tids = array();
|
||||
$query2 = $db->simple_select("threads", "tid,closed", "tid IN({$delayedmoderation['tids']})");
|
||||
while($thread = $db->fetch_array($query2))
|
||||
{
|
||||
if($thread['closed'] == 1)
|
||||
{
|
||||
$closed_tids[] = $thread['tid'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$open_tids[] = $thread['tid'];
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($closed_tids))
|
||||
{
|
||||
$moderation->open_threads($closed_tids);
|
||||
}
|
||||
|
||||
if(!empty($open_tids))
|
||||
{
|
||||
$moderation->close_threads($open_tids);
|
||||
}
|
||||
break;
|
||||
case "deletethread":
|
||||
foreach($tids as $tid)
|
||||
{
|
||||
$moderation->delete_thread($tid);
|
||||
}
|
||||
break;
|
||||
case "move":
|
||||
foreach($tids as $tid)
|
||||
{
|
||||
$moderation->move_thread($tid, $input['new_forum']);
|
||||
}
|
||||
break;
|
||||
case "stick":
|
||||
$unstuck_tids = $stuck_tids = array();
|
||||
$query2 = $db->simple_select("threads", "tid,sticky", "tid IN({$delayedmoderation['tids']})");
|
||||
while($thread = $db->fetch_array($query2))
|
||||
{
|
||||
if($thread['sticky'] == 1)
|
||||
{
|
||||
$stuck_tids[] = $thread['tid'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$unstuck_tids[] = $thread['tid'];
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($stuck_tids))
|
||||
{
|
||||
$moderation->unstick_threads($stuck_tids);
|
||||
}
|
||||
|
||||
if(!empty($unstuck_tids))
|
||||
{
|
||||
$moderation->stick_threads($unstuck_tids);
|
||||
}
|
||||
break;
|
||||
case "merge":
|
||||
// $delayedmoderation['tids'] should be a single tid
|
||||
if(count($tids) != 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// explode at # sign in a url (indicates a name reference) and reassign to the url
|
||||
$realurl = explode("#", $input['threadurl']);
|
||||
$input['threadurl'] = $realurl[0];
|
||||
|
||||
// Are we using an SEO URL?
|
||||
if(substr($input['threadurl'], -4) == "html")
|
||||
{
|
||||
// Get thread to merge's tid the SEO way
|
||||
preg_match("#thread-([0-9]+)?#i", $input['threadurl'], $threadmatch);
|
||||
preg_match("#post-([0-9]+)?#i", $input['threadurl'], $postmatch);
|
||||
|
||||
if($threadmatch[1])
|
||||
{
|
||||
$parameters['tid'] = $threadmatch[1];
|
||||
}
|
||||
|
||||
if($postmatch[1])
|
||||
{
|
||||
$parameters['pid'] = $postmatch[1];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get thread to merge's tid the normal way
|
||||
$splitloc = explode(".php", $input['threadurl']);
|
||||
$temp = explode("&", my_substr($splitloc[1], 1));
|
||||
|
||||
if(!empty($temp))
|
||||
{
|
||||
for($i = 0; $i < count($temp); $i++)
|
||||
{
|
||||
$temp2 = explode("=", $temp[$i], 2);
|
||||
$parameters[$temp2[0]] = $temp2[1];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$temp2 = explode("=", $splitloc[1], 2);
|
||||
$parameters[$temp2[0]] = $temp2[1];
|
||||
}
|
||||
}
|
||||
|
||||
if($parameters['pid'] && !$parameters['tid'])
|
||||
{
|
||||
$post = get_post($parameters['pid']);
|
||||
$mergetid = $post['tid'];
|
||||
}
|
||||
else if($parameters['tid'])
|
||||
{
|
||||
$mergetid = $parameters['tid'];
|
||||
}
|
||||
|
||||
$mergetid = (int)$mergetid;
|
||||
$mergethread = get_thread($mergetid);
|
||||
|
||||
if(!$mergethread['tid'])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if($mergetid == $delayedmoderation['tids'])
|
||||
{
|
||||
// sanity check
|
||||
continue;
|
||||
}
|
||||
|
||||
if($input['subject'])
|
||||
{
|
||||
$subject = $input['subject'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$query = $db->simple_select("threads", "subject", "tid='{$delayedmoderation['tids']}'");
|
||||
$subject = $db->fetch_field($query, "subject");
|
||||
}
|
||||
|
||||
$moderation->merge_threads($mergetid, $delayedmoderation['tids'], $subject);
|
||||
break;
|
||||
case "removeredirects":
|
||||
foreach($tids as $tid)
|
||||
{
|
||||
$moderation->remove_redirects($tid);
|
||||
}
|
||||
break;
|
||||
case "removesubscriptions":
|
||||
$moderation->remove_thread_subscriptions($tids, true);
|
||||
break;
|
||||
case "approveunapprovethread":
|
||||
$approved_tids = $unapproved_tids = array();
|
||||
$query2 = $db->simple_select("threads", "tid,visible", "tid IN({$delayedmoderation['tids']})");
|
||||
while($thread = $db->fetch_array($query2))
|
||||
{
|
||||
if($thread['visible'] == 1)
|
||||
{
|
||||
$approved_tids[] = $thread['tid'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$unapproved_tids[] = $thread['tid'];
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($approved_tids))
|
||||
{
|
||||
$moderation->unapprove_threads($approved_tids);
|
||||
}
|
||||
|
||||
if(!empty($unapproved_tids))
|
||||
{
|
||||
$moderation->approve_threads($unapproved_tids);
|
||||
}
|
||||
break;
|
||||
case "softdeleterestorethread":
|
||||
$delete_tids = $restore_tids = array();
|
||||
$query2 = $db->simple_select("threads", "tid,visible", "tid IN({$delayedmoderation['tids']})");
|
||||
while($thread = $db->fetch_array($query2))
|
||||
{
|
||||
if($thread['visible'] == -1)
|
||||
{
|
||||
$restore_tids[] = $thread['tid'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$delete_tids[] = $thread['tid'];
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($restore_tids))
|
||||
{
|
||||
$moderation->restore_threads($restore_tids);
|
||||
}
|
||||
|
||||
if(!empty($delete_tids))
|
||||
{
|
||||
$moderation->soft_delete_threads($delete_tids);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$db->delete_query("delayedmoderation", "did='{$delayedmoderation['did']}'");
|
||||
}
|
||||
|
||||
add_task_log($task, $lang->task_delayedmoderation_ran);
|
||||
}
|
||||
53
webroot/forum/inc/tasks/hourlycleanup.php
Normal file
53
webroot/forum/inc/tasks/hourlycleanup.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* MyBB 1.8
|
||||
* Copyright 2014 MyBB Group, All Rights Reserved
|
||||
*
|
||||
* Website: http://www.mybb.com
|
||||
* License: http://www.mybb.com/about/license
|
||||
*
|
||||
*/
|
||||
|
||||
function task_hourlycleanup($task)
|
||||
{
|
||||
global $db, $lang, $plugins;
|
||||
|
||||
$time = array(
|
||||
'threads' => TIME_NOW,
|
||||
'searchlog' => TIME_NOW-(60*60*24),
|
||||
'captcha' => TIME_NOW-(60*60*24),
|
||||
'question' => TIME_NOW-(60*60*24)
|
||||
);
|
||||
|
||||
if(is_object($plugins))
|
||||
{
|
||||
$args = array(
|
||||
'task' => &$task,
|
||||
'time' => &$time
|
||||
);
|
||||
$plugins->run_hooks('task_hourlycleanup', $args);
|
||||
}
|
||||
|
||||
require_once MYBB_ROOT."inc/class_moderation.php";
|
||||
$moderation = new Moderation;
|
||||
|
||||
// Delete moved threads with time limits
|
||||
$query = $db->simple_select('threads', 'tid', "deletetime != '0' AND deletetime < '".(int)$time['threads']."'");
|
||||
while($tid = $db->fetch_field($query, 'tid'))
|
||||
{
|
||||
$moderation->delete_thread($tid);
|
||||
}
|
||||
|
||||
// Delete old searches
|
||||
$db->delete_query("searchlog", "dateline < '".(int)$time['searchlog']."'");
|
||||
|
||||
// Delete old captcha images
|
||||
$cut = TIME_NOW-(60*60*24*7);
|
||||
$db->delete_query("captcha", "dateline < '".(int)$time['captcha']."'");
|
||||
|
||||
// Delete old registration questions
|
||||
$cut = TIME_NOW-(60*60*24*7);
|
||||
$db->delete_query("questionsessions", "dateline < '".(int)$time['question']."'");
|
||||
|
||||
add_task_log($task, $lang->task_hourlycleanup_ran);
|
||||
}
|
||||
8
webroot/forum/inc/tasks/index.html
Normal file
8
webroot/forum/inc/tasks/index.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<head>
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
63
webroot/forum/inc/tasks/logcleanup.php
Normal file
63
webroot/forum/inc/tasks/logcleanup.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* MyBB 1.8
|
||||
* Copyright 2014 MyBB Group, All Rights Reserved
|
||||
*
|
||||
* Website: http://www.mybb.com
|
||||
* License: http://www.mybb.com/about/license
|
||||
*
|
||||
*/
|
||||
|
||||
function task_logcleanup($task)
|
||||
{
|
||||
global $mybb, $db, $lang, $plugins;
|
||||
|
||||
// Clear out old admin logs
|
||||
if($mybb->config['log_pruning']['admin_logs'] > 0)
|
||||
{
|
||||
$cut = TIME_NOW-60*60*24*$mybb->config['log_pruning']['admin_logs'];
|
||||
$db->delete_query("adminlog", "dateline<'{$cut}'");
|
||||
}
|
||||
|
||||
// Clear out old moderator logs
|
||||
if($mybb->config['log_pruning']['mod_logs'] > 0)
|
||||
{
|
||||
$cut = TIME_NOW-60*60*24*$mybb->config['log_pruning']['mod_logs'];
|
||||
$db->delete_query("moderatorlog", "dateline<'{$cut}'");
|
||||
}
|
||||
|
||||
// Clear out old task logs
|
||||
if($mybb->config['log_pruning']['task_logs'] > 0)
|
||||
{
|
||||
$cut = TIME_NOW-60*60*24*$mybb->config['log_pruning']['task_logs'];
|
||||
$db->delete_query("tasklog", "dateline<'{$cut}'");
|
||||
}
|
||||
|
||||
// Clear out old mail error logs
|
||||
if($mybb->config['log_pruning']['mail_logs'] > 0)
|
||||
{
|
||||
$cut = TIME_NOW-60*60*24*$mybb->config['log_pruning']['mail_logs'];
|
||||
$db->delete_query("mailerrors", "dateline<'{$cut}'");
|
||||
}
|
||||
|
||||
// Clear out old user mail logs
|
||||
if($mybb->config['log_pruning']['user_mail_logs'] > 0)
|
||||
{
|
||||
$cut = TIME_NOW-60*60*24*$mybb->config['log_pruning']['user_mail_logs'];
|
||||
$db->delete_query("maillogs", "dateline<'{$cut}'");
|
||||
}
|
||||
|
||||
// Clear out old promotion logs
|
||||
if($mybb->config['log_pruning']['promotion_logs'] > 0)
|
||||
{
|
||||
$cut = TIME_NOW-60*60*24*$mybb->config['log_pruning']['promotion_logs'];
|
||||
$db->delete_query("promotionlogs", "dateline<'{$cut}'");
|
||||
}
|
||||
|
||||
if(is_object($plugins))
|
||||
{
|
||||
$plugins->run_hooks('task_logcleanup', $task);
|
||||
}
|
||||
|
||||
add_task_log($task, $lang->task_logcleanup_ran);
|
||||
}
|
||||
150
webroot/forum/inc/tasks/massmail.php
Normal file
150
webroot/forum/inc/tasks/massmail.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
/**
|
||||
* MyBB 1.8
|
||||
* Copyright 2014 MyBB Group, All Rights Reserved
|
||||
*
|
||||
* Website: http://www.mybb.com
|
||||
* License: http://www.mybb.com/about/license
|
||||
*
|
||||
*/
|
||||
|
||||
// Disallow direct access to this file for security reasons
|
||||
if(!defined("IN_MYBB"))
|
||||
{
|
||||
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
|
||||
}
|
||||
|
||||
require_once MYBB_ROOT."/inc/functions_massmail.php";
|
||||
require_once MYBB_ROOT."inc/datahandlers/pm.php";
|
||||
|
||||
function task_massmail($task)
|
||||
{
|
||||
global $db, $mybb, $lang, $plugins;
|
||||
|
||||
$query = $db->simple_select("massemails", "*", "senddate <= '".TIME_NOW."' AND status IN (1,2)");
|
||||
while($mass_email = $db->fetch_array($query))
|
||||
{
|
||||
if(is_object($plugins))
|
||||
{
|
||||
$args = array(
|
||||
'task' => &$task,
|
||||
'mass_email' => &$mass_email
|
||||
);
|
||||
$plugins->run_hooks('task_massmail', $args);
|
||||
}
|
||||
|
||||
if($mass_email['status'] == 1)
|
||||
{
|
||||
$db->update_query("massemails", array('status' => 2), "mid='{$mass_email['mid']}'");
|
||||
}
|
||||
|
||||
$sentcount = 0;
|
||||
|
||||
if(!$mass_email['perpage'])
|
||||
{
|
||||
$mass_email['perpage'] = 50;
|
||||
}
|
||||
|
||||
if(strpos($mass_email['htmlmessage'], '<br />') === false && strpos($mass_email['htmlmessage'], '<br>') === false)
|
||||
{
|
||||
$mass_email['htmlmessage'] = nl2br($mass_email['htmlmessage']);
|
||||
}
|
||||
|
||||
$mass_email['orig_message'] = $mass_email['message'];
|
||||
$mass_email['orig_htmlmessage'] = $mass_email['htmlmessage'];
|
||||
|
||||
// Need to perform the search to fetch the number of users we're emailing
|
||||
$member_query = build_mass_mail_query(my_unserialize($mass_email['conditions']));
|
||||
|
||||
$count_query = $db->simple_select("users u", "COUNT(uid) AS num", $member_query);
|
||||
$mass_email['totalcount'] = $db->fetch_field($count_query, "num");
|
||||
|
||||
$query2 = $db->simple_select("users u", "u.uid, u.language, u.pmnotify, u.lastactive, u.username, u.email", $member_query, array('limit_start' => $mass_email['sentcount'], 'limit' => $mass_email['perpage'], 'order_by' => 'u.uid', 'order_dir' => 'asc'));
|
||||
while($user = $db->fetch_array($query2))
|
||||
{
|
||||
$replacement_fields = array(
|
||||
"{uid}" => $user['uid'],
|
||||
"{username}" => $user['username'],
|
||||
"{email}" => $user['email'],
|
||||
"{bbname}" => $mybb->settings['bbname'],
|
||||
"{bburl}" => $mybb->settings['bburl'],
|
||||
"[".$lang->massmail_username."]" => $user['username'],
|
||||
"[".$lang->email_addr."]" => $user['email'],
|
||||
"[".$lang->board_name."]" => $mybb->settings['bbname'],
|
||||
"[".$lang->board_url."]" => $mybb->settings['bburl']
|
||||
);
|
||||
|
||||
foreach($replacement_fields as $find => $replace)
|
||||
{
|
||||
$mass_email['message'] = str_replace($find, $replace, $mass_email['message']);
|
||||
$mass_email['htmlmessage'] = str_replace($find, $replace, $mass_email['htmlmessage']);
|
||||
}
|
||||
|
||||
// Private Message
|
||||
if($mass_email['type'] == 1)
|
||||
{
|
||||
$pm_handler = new PMDataHandler();
|
||||
$pm_handler->admin_override = true;
|
||||
|
||||
$pm = array(
|
||||
"subject" => $mass_email['subject'],
|
||||
"message" => $mass_email['message'],
|
||||
"fromid" => $mass_email['uid'],
|
||||
"options" => array("savecopy" => 0),
|
||||
);
|
||||
|
||||
$pm['to'] = explode(",", $user['username']);
|
||||
$pm_handler->set_data($pm);
|
||||
if(!$pm_handler->validate_pm())
|
||||
{
|
||||
$friendly_errors = implode('\n', $pm_handler->get_friendly_errors());
|
||||
add_task_log($task, $lang->sprintf($lang->task_massmail_ran_errors, htmlspecialchars_uni($user['username']), $friendly_errors));
|
||||
$friendly_errors = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
$pm_handler->insert_pm();
|
||||
}
|
||||
}
|
||||
// Normal Email
|
||||
else
|
||||
{
|
||||
switch($mass_email['format'])
|
||||
{
|
||||
case 2:
|
||||
$format = "both";
|
||||
$text_message = $mass_email['message'];
|
||||
$mass_email['message'] = $mass_email['htmlmessage'];
|
||||
break;
|
||||
case 1:
|
||||
$format = "html";
|
||||
$text_message = "";
|
||||
$mass_email['message'] = $mass_email['htmlmessage'];
|
||||
break;
|
||||
default:
|
||||
$format = "text";
|
||||
$text_message = "";
|
||||
}
|
||||
my_mail($user['email'], $mass_email['subject'], $mass_email['message'], "", "", "", false, $format, $text_message);
|
||||
}
|
||||
++$sentcount;
|
||||
|
||||
$mass_email['message'] = $mass_email['orig_message'];
|
||||
$mass_email['htmlmessage'] = $mass_email['orig_htmlmessage'];
|
||||
}
|
||||
|
||||
$update_array = array();
|
||||
|
||||
$update_array['sentcount'] = $mass_email['sentcount'] + $sentcount;
|
||||
$update_array['totalcount'] = $mass_email['totalcount'];
|
||||
|
||||
if($update_array['sentcount'] >= $mass_email['totalcount'])
|
||||
{
|
||||
$update_array['status'] = 3;
|
||||
}
|
||||
|
||||
$db->update_query("massemails", $update_array, "mid='{$mass_email['mid']}'");
|
||||
}
|
||||
|
||||
add_task_log($task, $lang->task_massmail_ran);
|
||||
}
|
||||
255
webroot/forum/inc/tasks/promotions.php
Normal file
255
webroot/forum/inc/tasks/promotions.php
Normal file
@@ -0,0 +1,255 @@
|
||||
<?php
|
||||
/**
|
||||
* MyBB 1.8
|
||||
* Copyright 2014 MyBB Group, All Rights Reserved
|
||||
*
|
||||
* Website: http://www.mybb.com
|
||||
* License: http://www.mybb.com/about/license
|
||||
*
|
||||
*/
|
||||
|
||||
function task_promotions($task)
|
||||
{
|
||||
global $mybb, $db, $lang, $cache, $plugins;
|
||||
|
||||
$usergroups = $cache->read("usergroups");
|
||||
// Iterate through all our promotions
|
||||
$query = $db->simple_select("promotions", "*", "enabled = '1'");
|
||||
while($promotion = $db->fetch_array($query))
|
||||
{
|
||||
// Does the destination usergroup even exist?? If it doesn't and it moves a user to it, the user will get PHP errors.
|
||||
if(!array_key_exists($promotion['newusergroup'], $usergroups))
|
||||
{
|
||||
// Instead of just skipping this promotion, disable it to stop it even being selected when this task is run.
|
||||
$update = array(
|
||||
"enabled" => 0
|
||||
);
|
||||
$db->update_query("promotions", $update, "pid = '" . (int)$promotion['pid'] . "'");
|
||||
continue;
|
||||
}
|
||||
|
||||
$and = "";
|
||||
$sql_where = "";
|
||||
|
||||
// Based on the promotion generate criteria for user selection
|
||||
$requirements = explode(',', $promotion['requirements']);
|
||||
if(in_array('postcount', $requirements) && (int)$promotion['posts'] >= 0 && !empty($promotion['posttype']))
|
||||
{
|
||||
$sql_where .= "{$and}postnum {$promotion['posttype']} '{$promotion['posts']}'";
|
||||
|
||||
$and = " AND ";
|
||||
}
|
||||
|
||||
if(in_array('threadcount', $requirements) && (int)$promotion['threads'] >= 0 && !empty($promotion['threadtype']))
|
||||
{
|
||||
$sql_where .= "{$and}threadnum {$promotion['threadtype']} '{$promotion['threads']}'";
|
||||
|
||||
$and = " AND ";
|
||||
}
|
||||
|
||||
if(in_array('reputation', $requirements) && !empty($promotion['reputationtype']))
|
||||
{
|
||||
$sql_where .= "{$and}reputation {$promotion['reputationtype']} '{$promotion['reputations']}'";
|
||||
|
||||
$and = " AND ";
|
||||
}
|
||||
|
||||
if(in_array('referrals', $requirements) && (int)$promotion['referrals'] >= 0 && !empty($promotion['referralstype']))
|
||||
{
|
||||
$sql_where .= "{$and}referrals {$promotion['referralstype']} '{$promotion['referrals']}'";
|
||||
|
||||
$and = " AND ";
|
||||
}
|
||||
|
||||
if(in_array('warnings', $requirements) && (int)$promotion['warnings'] >= 0 && !empty($promotion['warningstype']))
|
||||
{
|
||||
$sql_where .= "{$and}warningpoints {$promotion['warningstype']} '{$promotion['warnings']}'";
|
||||
|
||||
$and = " AND ";
|
||||
}
|
||||
|
||||
if(in_array('timeregistered', $requirements) && (int)$promotion['registered'] > 0 && !empty($promotion['registeredtype']))
|
||||
{
|
||||
switch($promotion['registeredtype'])
|
||||
{
|
||||
case "hours":
|
||||
$regdate = $promotion['registered']*60*60;
|
||||
break;
|
||||
case "days":
|
||||
$regdate = $promotion['registered']*60*60*24;
|
||||
break;
|
||||
case "weeks":
|
||||
$regdate = $promotion['registered']*60*60*24*7;
|
||||
break;
|
||||
case "months":
|
||||
$regdate = $promotion['registered']*60*60*24*30;
|
||||
break;
|
||||
case "years":
|
||||
$regdate = $promotion['registered']*60*60*24*365;
|
||||
break;
|
||||
default:
|
||||
$regdate = $promotion['registered']*60*60*24;
|
||||
}
|
||||
$sql_where .= "{$and}regdate <= '".(TIME_NOW-$regdate)."'";
|
||||
$and = " AND ";
|
||||
}
|
||||
|
||||
if(in_array('timeonline', $requirements) && (int)$promotion['online'] > 0 && !empty($promotion['onlinetype']))
|
||||
{
|
||||
switch($promotion['onlinetype'])
|
||||
{
|
||||
case "hours":
|
||||
$timeonline = $promotion['online']*60*60;
|
||||
break;
|
||||
case "days":
|
||||
$timeonline = $promotion['online']*60*60*24;
|
||||
break;
|
||||
case "weeks":
|
||||
$timeonline = $promotion['online']*60*60*24*7;
|
||||
break;
|
||||
case "months":
|
||||
$timeonline = $promotion['online']*60*60*24*30;
|
||||
break;
|
||||
case "years":
|
||||
$timeonline = $promotion['online']*60*60*24*365;
|
||||
break;
|
||||
default:
|
||||
$timeonline = $promotion['online']*60*60*24;
|
||||
}
|
||||
$sql_where .= "{$and}timeonline <= '".(TIME_NOW-$timeonline)."'";
|
||||
$and = " AND ";
|
||||
}
|
||||
|
||||
if(!empty($promotion['originalusergroup']) && $promotion['originalusergroup'] != '*')
|
||||
{
|
||||
$sql_where .= "{$and}usergroup IN ({$promotion['originalusergroup']})";
|
||||
|
||||
$and = " AND ";
|
||||
}
|
||||
|
||||
if(!empty($promotion['newusergroup']))
|
||||
{
|
||||
// Skip users that are already in the new group
|
||||
switch($db->type)
|
||||
{
|
||||
case "pgsql":
|
||||
case "sqlite":
|
||||
$sql_where .= "{$and}usergroup != '{$promotion['newusergroup']}' AND ','||additionalgroups||',' NOT LIKE '%,{$promotion['newusergroup']},%'";
|
||||
break;
|
||||
default:
|
||||
$sql_where .= "{$and}usergroup != '{$promotion['newusergroup']}' AND CONCAT(',', additionalgroups, ',') NOT LIKE '%,{$promotion['newusergroup']},%'";
|
||||
}
|
||||
|
||||
$and = " AND ";
|
||||
}
|
||||
|
||||
$uid = array();
|
||||
$log_inserts = array();
|
||||
|
||||
if($promotion['usergrouptype'] == "secondary")
|
||||
{
|
||||
$usergroup_select = "additionalgroups";
|
||||
}
|
||||
else
|
||||
{
|
||||
$usergroup_select = "usergroup";
|
||||
}
|
||||
|
||||
if(is_object($plugins))
|
||||
{
|
||||
$args = array(
|
||||
'task' => &$task,
|
||||
'promotion' => &$promotion,
|
||||
'sql_where' => &$sql_where,
|
||||
'and' => &$and,
|
||||
'usergroup_select' => &$usergroup_select
|
||||
);
|
||||
$plugins->run_hooks('task_promotions', $args);
|
||||
}
|
||||
|
||||
$query2 = $db->simple_select("users", "uid,{$usergroup_select}", $sql_where);
|
||||
|
||||
$uids = array();
|
||||
while($user = $db->fetch_array($query2))
|
||||
{
|
||||
if(is_super_admin($user['uid']))
|
||||
{
|
||||
// Skip super admins
|
||||
continue;
|
||||
}
|
||||
|
||||
// super admin check?
|
||||
if($usergroup_select == "additionalgroups")
|
||||
{
|
||||
$log_inserts[] = array(
|
||||
'pid' => $promotion['pid'],
|
||||
'uid' => $user['uid'],
|
||||
'oldusergroup' => $user['additionalgroups'],
|
||||
'newusergroup' => $promotion['newusergroup'],
|
||||
'dateline' => TIME_NOW,
|
||||
'type' => "secondary",
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$log_inserts[] = array(
|
||||
'pid' => $promotion['pid'],
|
||||
'uid' => $user['uid'],
|
||||
'oldusergroup' => $user['usergroup'],
|
||||
'newusergroup' => $promotion['newusergroup'],
|
||||
'dateline' => TIME_NOW,
|
||||
'type' => "primary",
|
||||
);
|
||||
}
|
||||
|
||||
$uids[] = $user['uid'];
|
||||
|
||||
|
||||
if($usergroup_select == "additionalgroups")
|
||||
{
|
||||
if(join_usergroup($user['uid'], $promotion['newusergroup']) === false)
|
||||
{
|
||||
// Did the user already have the additional usergroup?
|
||||
array_pop($log_inserts);
|
||||
array_pop($uids);
|
||||
}
|
||||
}
|
||||
|
||||
if((count($uids) % 20) == 0)
|
||||
{
|
||||
if($usergroup_select == "usergroup")
|
||||
{
|
||||
$db->update_query("users", array('usergroup' => $promotion['newusergroup']), "uid IN(".implode(",", $uids).")");
|
||||
}
|
||||
|
||||
if(!empty($log_inserts))
|
||||
{
|
||||
$db->insert_query_multiple("promotionlogs", $log_inserts);
|
||||
}
|
||||
|
||||
$uids = array();
|
||||
$log_inserts = array();
|
||||
}
|
||||
}
|
||||
|
||||
if(count($uids) > 0)
|
||||
{
|
||||
if($usergroup_select == "usergroup")
|
||||
{
|
||||
$db->update_query("users", array('usergroup' => $promotion['newusergroup']), "uid IN(".implode(",", $uids).")");
|
||||
}
|
||||
|
||||
if(!empty($log_inserts))
|
||||
{
|
||||
$db->insert_query_multiple("promotionlogs", $log_inserts);
|
||||
}
|
||||
|
||||
$uids = array();
|
||||
$log_inserts = array();
|
||||
}
|
||||
}
|
||||
|
||||
$cache->update_moderators();
|
||||
|
||||
add_task_log($task, $lang->task_promotions_ran);
|
||||
}
|
||||
39
webroot/forum/inc/tasks/recachestylesheets.php
Normal file
39
webroot/forum/inc/tasks/recachestylesheets.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* MyBB 1.8
|
||||
* Copyright 2014 MyBB Group, All Rights Reserved
|
||||
*
|
||||
* Website: http://www.mybb.com
|
||||
* License: http://www.mybb.com/about/license
|
||||
*
|
||||
*/
|
||||
|
||||
function task_recachestylesheets($task)
|
||||
{
|
||||
global $mybb, $db, $lang;
|
||||
|
||||
if(file_exists(MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions_themes.php"))
|
||||
{
|
||||
require_once MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions_themes.php";
|
||||
}
|
||||
else if(file_exists(MYBB_ROOT."admin/inc/functions_themes.php"))
|
||||
{
|
||||
require_once MYBB_ROOT."admin/inc/functions_themes.php";
|
||||
}
|
||||
|
||||
$query = $db->simple_select('themestylesheets', '*');
|
||||
|
||||
$num_recached = 0;
|
||||
|
||||
while($stylesheet = $db->fetch_array($query))
|
||||
{
|
||||
if(cache_stylesheet($stylesheet['tid'], $stylesheet['name'], $stylesheet['stylesheet']))
|
||||
{
|
||||
$db->update_query("themestylesheets", array('cachefile' => $db->escape_string($stylesheet['name'])), "sid='{$stylesheet['sid']}'", 1);
|
||||
++$num_recached;
|
||||
}
|
||||
}
|
||||
|
||||
add_task_log($task, $lang->sprintf($lang->task_recachestylesheets_ran, $num_recached));
|
||||
}
|
||||
|
||||
35
webroot/forum/inc/tasks/threadviews.php
Normal file
35
webroot/forum/inc/tasks/threadviews.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* MyBB 1.8
|
||||
* Copyright 2014 MyBB Group, All Rights Reserved
|
||||
*
|
||||
* Website: http://www.mybb.com
|
||||
* License: http://www.mybb.com/about/license
|
||||
*
|
||||
*/
|
||||
|
||||
function task_threadviews($task)
|
||||
{
|
||||
global $mybb, $db, $lang, $plugins;
|
||||
|
||||
if($mybb->settings['delayedthreadviews'] != 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Update thread views
|
||||
$query = $db->simple_select("threadviews", "tid, COUNT(tid) AS views", "", array('group_by' => 'tid'));
|
||||
while($threadview = $db->fetch_array($query))
|
||||
{
|
||||
$db->update_query("threads", array('views' => "views+{$threadview['views']}"), "tid='{$threadview['tid']}'", 1, true);
|
||||
}
|
||||
|
||||
$db->write_query("TRUNCATE TABLE ".TABLE_PREFIX."threadviews");
|
||||
|
||||
if(is_object($plugins))
|
||||
{
|
||||
$plugins->run_hooks('task_threadviews', $task);
|
||||
}
|
||||
|
||||
add_task_log($task, $lang->task_threadviews_ran);
|
||||
}
|
||||
74
webroot/forum/inc/tasks/usercleanup.php
Normal file
74
webroot/forum/inc/tasks/usercleanup.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* MyBB 1.8
|
||||
* Copyright 2014 MyBB Group, All Rights Reserved
|
||||
*
|
||||
* Website: http://www.mybb.com
|
||||
* License: http://www.mybb.com/about/license
|
||||
*
|
||||
*/
|
||||
|
||||
function task_usercleanup($task)
|
||||
{
|
||||
global $db, $lang, $cache, $plugins;
|
||||
|
||||
// Expire any old warnings
|
||||
require_once MYBB_ROOT.'inc/datahandlers/warnings.php';
|
||||
$warningshandler = new WarningsHandler('update');
|
||||
|
||||
$warningshandler->expire_warnings();
|
||||
|
||||
// Expire any post moderation or suspension limits
|
||||
$query = $db->simple_select("users", "uid, moderationtime, suspensiontime", "(moderationtime!=0 AND moderationtime<".TIME_NOW.") OR (suspensiontime!=0 AND suspensiontime<".TIME_NOW.")");
|
||||
while($user = $db->fetch_array($query))
|
||||
{
|
||||
$updated_user = array();
|
||||
if($user['moderationtime'] != 0 && $user['moderationtime'] < TIME_NOW)
|
||||
{
|
||||
$updated_user['moderateposts'] = 0;
|
||||
$updated_user['moderationtime'] = 0;
|
||||
}
|
||||
if($user['suspensiontime'] != 0 && $user['suspensiontime'] < TIME_NOW)
|
||||
{
|
||||
$updated_user['suspendposting'] = 0;
|
||||
$updated_user['suspensiontime'] = 0;
|
||||
}
|
||||
$db->update_query("users", $updated_user, "uid='{$user['uid']}'");
|
||||
}
|
||||
|
||||
// Expire any suspended signatures
|
||||
$query = $db->simple_select("users", "uid, suspendsigtime", "suspendsignature != 0 AND suspendsigtime < '".TIME_NOW."'");
|
||||
while($user = $db->fetch_array($query))
|
||||
{
|
||||
if($user['suspendsigtime'] != 0 && $user['suspendsigtime'] < TIME_NOW)
|
||||
{
|
||||
$updated_user = array(
|
||||
"suspendsignature" => 0,
|
||||
"suspendsigtime" => 0,
|
||||
);
|
||||
$db->update_query("users", $updated_user, "uid='".$user['uid']."'");
|
||||
}
|
||||
}
|
||||
|
||||
// Expire bans
|
||||
$query = $db->simple_select("banned", "*", "lifted!=0 AND lifted<".TIME_NOW);
|
||||
while($ban = $db->fetch_array($query))
|
||||
{
|
||||
$updated_user = array(
|
||||
"usergroup" => $ban['oldgroup'],
|
||||
"additionalgroups" => $ban['oldadditionalgroups'],
|
||||
"displaygroup" => $ban['olddisplaygroup']
|
||||
);
|
||||
$db->update_query("users", $updated_user, "uid='{$ban['uid']}'");
|
||||
$db->delete_query("banned", "uid='{$ban['uid']}'");
|
||||
}
|
||||
|
||||
$cache->update_moderators();
|
||||
|
||||
if(is_object($plugins))
|
||||
{
|
||||
$plugins->run_hooks('task_usercleanup', $task);
|
||||
}
|
||||
|
||||
add_task_log($task, $lang->task_usercleanup_ran);
|
||||
}
|
||||
101
webroot/forum/inc/tasks/userpruning.php
Normal file
101
webroot/forum/inc/tasks/userpruning.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* MyBB 1.8
|
||||
* Copyright 2014 MyBB Group, All Rights Reserved
|
||||
*
|
||||
* Website: http://www.mybb.com
|
||||
* License: http://www.mybb.com/about/license
|
||||
*
|
||||
*/
|
||||
|
||||
function task_userpruning($task)
|
||||
{
|
||||
global $db, $lang, $mybb, $cache, $plugins;
|
||||
|
||||
if($mybb->settings['enablepruning'] != 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Are we pruning by posts?
|
||||
if($mybb->settings['enableprunebyposts'] == 1)
|
||||
{
|
||||
$in_usergroups = array();
|
||||
$users = array();
|
||||
|
||||
$usergroups = $cache->read('usergroups');
|
||||
foreach($usergroups as $gid => $usergroup)
|
||||
{
|
||||
// Exclude admin, moderators, super moderators, banned
|
||||
if($usergroup['canmodcp'] == 1 || $usergroup['cancp'] == 1 || $usergroup['issupermod'] == 1 || $usergroup['isbannedgroup'] == 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$in_usergroups[] = $gid;
|
||||
}
|
||||
|
||||
// If we're not pruning unactivated users, then remove them from the criteria
|
||||
if($mybb->settings['pruneunactived'] == 0)
|
||||
{
|
||||
$key = array_search('5', $in_usergroups);
|
||||
unset($in_usergroups[$key]);
|
||||
}
|
||||
|
||||
$prunepostcount = (int)$mybb->settings['prunepostcount'];
|
||||
|
||||
$regdate = TIME_NOW-((int)$mybb->settings['dayspruneregistered']*24*60*60);
|
||||
|
||||
$usergroups = $db->escape_string(implode(',', $in_usergroups));
|
||||
|
||||
$query = $db->simple_select('users', 'uid', "regdate<={$regdate} AND postnum<={$prunepostcount} AND usergroup IN({$usergroups})");
|
||||
while($uid = $db->fetch_field($query, 'uid'))
|
||||
{
|
||||
$users[$uid] = $uid;
|
||||
}
|
||||
|
||||
if($users && $mybb->settings['prunepostcountall'])
|
||||
{
|
||||
$query = $db->simple_select('posts', 'uid, COUNT(pid) as posts', "uid IN ('".implode("','", $users)."') AND visible>0", array('group_by' => 'uid'));
|
||||
while($user = $db->fetch_array($query))
|
||||
{
|
||||
if($user['posts'] >= $prunepostcount)
|
||||
{
|
||||
unset($users[$user['uid']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Are we pruning unactivated users?
|
||||
if($mybb->settings['pruneunactived'] == 1)
|
||||
{
|
||||
$regdate = TIME_NOW-((int)$mybb->settings['dayspruneunactivated']*24*60*60);
|
||||
$query = $db->simple_select("users", "uid", "regdate<={$regdate} AND usergroup='5'");
|
||||
while($user = $db->fetch_array($query))
|
||||
{
|
||||
$users[$user['uid']] = $user['uid'];
|
||||
}
|
||||
}
|
||||
|
||||
if(is_object($plugins))
|
||||
{
|
||||
$args = array(
|
||||
'task' => &$task,
|
||||
'in_usergroups' => &$in_usergroups,
|
||||
'users' => &$users,
|
||||
);
|
||||
$plugins->run_hooks('task_userpruning', $args);
|
||||
}
|
||||
|
||||
if(!empty($users))
|
||||
{
|
||||
// Set up user handler.
|
||||
require_once MYBB_ROOT.'inc/datahandlers/user.php';
|
||||
$userhandler = new UserDataHandler('delete');
|
||||
|
||||
// Delete the prunned users
|
||||
$userhandler->delete_user($users, $mybb->settings['prunethreads']);
|
||||
}
|
||||
|
||||
add_task_log($task, $lang->task_userpruning_ran);
|
||||
}
|
||||
91
webroot/forum/inc/tasks/versioncheck.php
Normal file
91
webroot/forum/inc/tasks/versioncheck.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* MyBB 1.8
|
||||
* Copyright 2014 MyBB Group, All Rights Reserved
|
||||
*
|
||||
* Website: http://www.mybb.com
|
||||
* License: http://www.mybb.com/about/license
|
||||
*
|
||||
*/
|
||||
|
||||
function task_versioncheck($task)
|
||||
{
|
||||
global $cache, $lang, $mybb;
|
||||
|
||||
$current_version = rawurlencode($mybb->version_code);
|
||||
|
||||
$updated_cache = array(
|
||||
'last_check' => TIME_NOW
|
||||
);
|
||||
|
||||
// Check for the latest version
|
||||
require_once MYBB_ROOT.'inc/class_xml.php';
|
||||
$contents = fetch_remote_file("https://mybb.com/version_check.php");
|
||||
|
||||
if(!$contents)
|
||||
{
|
||||
add_task_log($task, $lang->task_versioncheck_ran_errors);
|
||||
return false;
|
||||
}
|
||||
|
||||
$contents = trim($contents);
|
||||
|
||||
$parser = new XMLParser($contents);
|
||||
$tree = $parser->get_tree();
|
||||
|
||||
$latest_code = (int)$tree['mybb']['version_code']['value'];
|
||||
$latest_version = "<strong>".htmlspecialchars_uni($tree['mybb']['latest_version']['value'])."</strong> (".$latest_code.")";
|
||||
if($latest_code > $mybb->version_code)
|
||||
{
|
||||
$latest_version = "<span style=\"color: #C00;\">".$latest_version."</span>";
|
||||
$version_warn = 1;
|
||||
$updated_cache['latest_version'] = $latest_version;
|
||||
$updated_cache['latest_version_code'] = $latest_code;
|
||||
}
|
||||
else
|
||||
{
|
||||
$latest_version = "<span style=\"color: green;\">".$latest_version."</span>";
|
||||
}
|
||||
|
||||
// Check for the latest news
|
||||
require_once MYBB_ROOT."inc/class_feedparser.php";
|
||||
|
||||
$feed_parser = new FeedParser();
|
||||
$feed_parser->parse_feed("http://feeds.feedburner.com/MyBBDevelopmentBlog");
|
||||
|
||||
$updated_cache['news'] = array();
|
||||
|
||||
require_once MYBB_ROOT . '/inc/class_parser.php';
|
||||
$post_parser = new postParser();
|
||||
|
||||
if($feed_parser->error == '')
|
||||
{
|
||||
foreach($feed_parser->items as $item)
|
||||
{
|
||||
if (isset($updated_cache['news'][2]))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
$description = $item['description'];
|
||||
|
||||
$description = $post_parser->parse_message($description, array(
|
||||
'allow_html' => true,
|
||||
)
|
||||
);
|
||||
|
||||
$description = preg_replace('#<img(.*)/>#', '', $description);
|
||||
|
||||
$updated_cache['news'][] = array(
|
||||
'title' => htmlspecialchars_uni($item['title']),
|
||||
'description' => $description,
|
||||
'link' => htmlspecialchars_uni($item['link']),
|
||||
'author' => htmlspecialchars_uni($item['author']),
|
||||
'dateline' => $item['date_timestamp']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$cache->update("update_check", $updated_cache);
|
||||
add_task_log($task, $lang->task_versioncheck_ran);
|
||||
}
|
||||
Reference in New Issue
Block a user