public function setTheme($name) { if (D('Config')->where(array('name' => '_THEME_NOW_THEME'))->count()) { $res = D('Config')->where(array('name' => '_THEME_NOW_THEME'))->setField('value', $name); } else { $config['name'] = '_THEME_NOW_THEME'; $config['type'] = 0; $config['title'] = ''; $config['group'] = 0; $config['extra'] = ''; $config['remark'] = ''; $config['create_time'] = time(); $config['update_time'] = time(); $config['status'] = 1; $config['value'] = $name; $config['sort'] = 0; $res = D('Config')->add($config); } if ($res) { S('conf_THEME_NOW_THEME', $name); cookie('TO_LOOK_THEME', $name, array('prefix' => 'OSV2')); clean_cache(RUNTIME_PATH . 'Cache/'); //清除模板缓存 return true; } else { $this->error = L('_WRITE_DATABASE_FAILURE_WITH_PERIOD_'); return false; } }
function cache_check_diskspace2() { $too_old = 86400; while (1) { $f = disk_free_space("../cache"); $u = disk_usage("../cache"); echo "free: {$f} used: {$u}\n"; if ($f > MIN_FREE_SPACE && $u < MAX_CACHE_USAGE) { break; } clean_cache($too_old, "../cache"); $too_old /= 2; } }
function KB_cleanCache() { global $cachedir; if (!is_dir($cachedir)) { return; } $files = scandir($cachedir); $failed = true; foreach ($files as $key => $value) { if (strpos($value, 'kb_') && $value != 'index.php' && $value != '.htaccess') { @unlink($cachedir . '/' . $value); $failed = false; } } if ($failed == true) { //fall back just incase you never know :P clean_cache(); } }
/** * @param bool $return_config * @return array config vars */ function addMenuButtonWithBoardsListAdminSettings($return_config = false) { global $txt, $scripturl, $context; loadLanguage('MenuButtonWithBoardsList/'); $context['page_title'] = $txt['menu_button_with_boards']; $context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=menu_button_with_boards'; $context['settings_message'] = ''; $config_vars = array(array('title', 'menu_button_with_boards_settings'), array('text', 'menu_button_with_boards_title'), array('text', 'menu_button_with_boards_cats', 'subtext' => $txt['menu_button_with_boards_cats_desc'])); if ($return_config) { return $config_vars; } if (isset($_GET['save'])) { checkSession(); saveDBSettings($config_vars); clean_cache(); redirectexit('action=admin;area=modsettings;sa=menu_button_with_boards'); } prepareDBSettingContext($config_vars); }
/** * 升级完成 */ public function finish() { $nextVersion = $_SESSION['nextVersion']; $currentVersion = $_SESSION['currentVersion']; $versionModel = M('Version'); $versionModel->where(array('name' => $nextVersion['name']))->setField('update_time', time()); $versionModel->setCurrentVersion($nextVersion['name']); $this->assign('currentVersion', $versionModel->getCurrentVersion()); $new_file_path = C('UPDATE_PATH') . $_SESSION['nextVersion']['name']; $this->assign('path', $new_file_path); $this->disableCheckUpdate(); $versionModel->cleanCheckUpdateCache(); clean_cache(); $this->display(); }
function scheduled_daily_maintenance() { global $modSettings, $sourcedir, $db_type; // First clean out the cache. clean_cache(); // If warning decrement is enabled and we have people who have not had a new warning in 24 hours, lower their warning level. list(, , $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']); if ($modSettings['warning_decrement']) { // Find every member who has a warning level... $request = smf_db_query(' SELECT id_member, warning FROM {db_prefix}members WHERE warning > {int:no_warning}', array('no_warning' => 0)); $members = array(); while ($row = mysql_fetch_assoc($request)) { $members[$row['id_member']] = $row['warning']; } mysql_free_result($request); // Have some members to check? if (!empty($members)) { // Find out when they were last warned. $request = smf_db_query(' SELECT id_recipient, MAX(log_time) AS last_warning FROM {db_prefix}log_comments WHERE id_recipient IN ({array_int:member_list}) AND comment_type = {string:warning} GROUP BY id_recipient', array('member_list' => array_keys($members), 'warning' => 'warning')); $member_changes = array(); while ($row = mysql_fetch_assoc($request)) { // More than 24 hours ago? if ($row['last_warning'] <= time() - 86400) { $member_changes[] = array('id' => $row['id_recipient'], 'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0); } } mysql_free_result($request); // Have some members to change? if (!empty($member_changes)) { foreach ($member_changes as $change) { smf_db_query(' UPDATE {db_prefix}members SET warning = {int:warning} WHERE id_member = {int:id_member}', array('warning' => $change['warning'], 'id_member' => $change['id'])); } } } } // Do any spider stuff. if (!empty($modSettings['spider_mode']) && $modSettings['spider_mode'] > 1) { require_once $sourcedir . '/ManageSearchEngines.php'; consolidateSpiderStats(); } // Check the database version - for some buggy MySQL version. $server_version = mysql_get_server_info(); if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { updateSettings(array('db_mysql_group_by_fix' => '1')); } elseif (!empty($modSettings['db_mysql_group_by_fix'])) { smf_db_query(' DELETE FROM {db_prefix}settings WHERE variable = {string:mysql_fix}', array('mysql_fix' => 'db_mysql_group_by_fix')); } // Regenerate the Diffie-Hellman keys if OpenID is enabled. if (!empty($modSettings['enableOpenID'])) { require_once $sourcedir . '/lib/Subs-OpenID.php'; smf_openID_setup_DH(true); } elseif (!empty($modSettings['dh_keys'])) { smf_db_query(' DELETE FROM {db_prefix}settings WHERE variable = {string:dh_keys}', array('dh_keys' => 'dh_keys')); } // clean out old cached posts if ($modSettings['post_cache_cutoff'] < 10) { $modSettings['post_cache_cutoff'] = 10; } smf_db_query(' DELETE FROM {db_prefix}messages_cache WHERE updated < {int:cutoff}', array('cutoff' => time() - $modSettings['post_cache_cutoff'] * 86400)); // auto-expire topicbans (expires == 0 means the ban is permanent until lifted manually, so do not expire them) smf_db_query('DELETE FROM {db_prefix}topicbans WHERE expires <> 0 AND expires <= UNIX_TIMESTAMP(NOW())'); HookAPI::callHook('sys_daily_maint'); // Log we've done it... return true; }
function db_debug_junk() { global $context, $scripturl, $boarddir, $modSettings, $boarddir; global $db_cache, $db_count, $db_show_debug, $cache_count, $cache_hits, $txt; // Add to Settings.php if you want to show the debugging information. if (!isset($db_show_debug) || $db_show_debug !== true || isset($_GET['action']) && $_GET['action'] == 'viewquery' || WIRELESS) { return; } if (empty($_SESSION['view_queries'])) { $_SESSION['view_queries'] = 0; } if (empty($context['debug']['language_files'])) { $context['debug']['language_files'] = array(); } if (empty($context['debug']['sheets'])) { $context['debug']['sheets'] = array(); } $files = get_included_files(); $total_size = 0; for ($i = 0, $n = count($files); $i < $n; $i++) { if (file_exists($files[$i])) { $total_size += filesize($files[$i]); } $files[$i] = strtr($files[$i], array($boarddir => '.')); } $warnings = 0; if (!empty($db_cache)) { foreach ($db_cache as $q => $qq) { if (!empty($qq['w'])) { $warnings += count($qq['w']); } } $_SESSION['debug'] =& $db_cache; } // Gotta have valid HTML ;). $temp = ob_get_contents(); if (function_exists('ob_clean')) { ob_clean(); } else { ob_end_clean(); ob_start('ob_sessrewrite'); } echo preg_replace('~</body>\\s*</html>~', '', $temp), ' <div class="smalltext" style="text-align: left; margin: 1ex;"> ', $txt['debug_templates'], count($context['debug']['templates']), ': <em>', implode('</em>, <em>', $context['debug']['templates']), '</em>.<br /> ', $txt['debug_subtemplates'], count($context['debug']['sub_templates']), ': <em>', implode('</em>, <em>', $context['debug']['sub_templates']), '</em>.<br /> ', $txt['debug_language_files'], count($context['debug']['language_files']), ': <em>', implode('</em>, <em>', $context['debug']['language_files']), '</em>.<br /> ', $txt['debug_stylesheets'], count($context['debug']['sheets']), ': <em>', implode('</em>, <em>', $context['debug']['sheets']), '</em>.<br /> ', $txt['debug_files_included'], count($files), ' - ', round($total_size / 1024), $txt['debug_kb'], ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_include_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_include_info" style="display: none;"><em>', implode('</em>, <em>', $files), '</em></span>)<br />'; if (!empty($modSettings['cache_enable']) && !empty($cache_hits)) { $entries = array(); $total_t = 0; $total_s = 0; foreach ($cache_hits as $cache_hit) { $entries[] = $cache_hit['d'] . ' ' . $cache_hit['k'] . ': ' . sprintf($txt['debug_cache_seconds_bytes'], comma_format($cache_hit['t'], 5), $cache_hit['s']); $total_t += $cache_hit['t']; $total_s += $cache_hit['s']; } echo ' ', $txt['debug_cache_hits'], $cache_count, ': ', sprintf($txt['debug_cache_seconds_bytes_total'], comma_format($total_t, 5), comma_format($total_s)), ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_cache_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_cache_info" style="display: none;"><em>', implode('</em>, <em>', $entries), '</em></span>)<br />'; } echo ' <a href="', $scripturl, '?action=viewquery" target="_blank" class="new_win">', $warnings == 0 ? sprintf($txt['debug_queries_used'], (int) $db_count) : sprintf($txt['debug_queries_used_and_warnings'], (int) $db_count, $warnings), '</a><br /> <br />'; if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) { foreach ($db_cache as $q => $qq) { $is_select = substr(trim($qq['q']), 0, 6) == 'SELECT' || preg_match('~^INSERT(?: IGNORE)? INTO \\w+(?:\\s+\\([^)]+\\))?\\s+SELECT .+$~s', trim($qq['q'])) != 0; // Temporary tables created in earlier queries are not explainable. if ($is_select) { foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) { if (strpos(trim($qq['q']), $tmp) !== false) { $is_select = false; break; } } } elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($qq['q'])) != 0) { $is_select = true; } // Make the filenames look a bit better. if (isset($qq['f'])) { $qq['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $qq['f']); } echo ' <strong>', $is_select ? '<a href="' . $scripturl . '?action=viewquery;qq=' . ($q + 1) . '#qq' . $q . '" target="_blank" class="new_win" style="text-decoration: none;">' : '', nl2br(str_replace("\t", ' ', htmlspecialchars(ltrim($qq['q'], "\n\r")))) . ($is_select ? '</a></strong>' : '</strong>') . '<br /> '; if (!empty($qq['f']) && !empty($qq['l'])) { echo sprintf($txt['debug_query_in_line'], $qq['f'], $qq['l']); } if (isset($qq['s'], $qq['t']) && isset($txt['debug_query_which_took_at'])) { echo sprintf($txt['debug_query_which_took_at'], round($qq['t'], 8), round($qq['s'], 8)) . '<br />'; } elseif (isset($qq['t'])) { echo sprintf($txt['debug_query_which_took'], round($qq['t'], 8)) . '<br />'; } echo ' <br />'; } } echo ' <a href="' . $scripturl . '?action=viewquery;sa=hide">', $txt['debug_' . (empty($_SESSION['view_queries']) ? 'show' : 'hide') . '_queries'], '</a> </div></body></html>'; // Empty the language cache, if (isset($_REQUEST['clearcache'])) { clean_cache('lang'); } }
function RemoveTheme() { global $modSettings, $context, $smcFunc; checkSession('get'); isAllowedTo('admin_forum'); // The theme's ID must be an integer. $_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id']; // You can't delete the default theme! if ($_GET['th'] == 1) { fatal_lang_error('no_access', false); } $known = explode(',', $modSettings['knownThemes']); for ($i = 0, $n = count($known); $i < $n; $i++) { if ($known[$i] == $_GET['th']) { unset($known[$i]); } } $smcFunc['db_query']('', ' DELETE FROM {db_prefix}themes WHERE id_theme = {int:current_theme}', array('current_theme' => $_GET['th'])); $smcFunc['db_query']('', ' UPDATE {db_prefix}members SET id_theme = {int:default_theme} WHERE id_theme = {int:current_theme}', array('default_theme' => 0, 'current_theme' => $_GET['th'])); $smcFunc['db_query']('', ' UPDATE {db_prefix}boards SET id_theme = {int:default_theme} WHERE id_theme = {int:current_theme}', array('default_theme' => 0, 'current_theme' => $_GET['th'])); $known = strtr(implode(',', $known), array(',,' => ',')); // Fix it if the theme was the overall default theme. if ($modSettings['theme_guests'] == $_GET['th']) { updateSettings(array('theme_guests' => '1', 'knownThemes' => $known)); } else { updateSettings(array('knownThemes' => $known)); } // Remove any cached language files to keep space minimum! clean_cache('lang'); redirectexit('action=admin;area=theme;sa=list;' . $context['session_var'] . '=' . $context['session_id']); }
function PackageInstall() { global $boarddir, $txt, $context, $boardurl, $scripturl, $sourcedir, $modSettings; global $user_info, $smcFunc; // Make sure we don't install this mod twice. checkSubmitOnce('check'); checkSession(); // If there's no file, what are we installing? if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') { redirectexit('action=admin;area=packages'); } $context['filename'] = $_REQUEST['package']; // If this is an uninstall, we'll have an id. $context['install_id'] = isset($_REQUEST['pid']) ? (int) $_REQUEST['pid'] : 0; require_once $sourcedir . '/lib/Subs-Package.php'; // !!! TODO: Perhaps do it in steps, if necessary? $context['uninstalling'] = $_REQUEST['sa'] == 'uninstall2'; // Set up the linktree for other. $context['linktree'][count($context['linktree']) - 1] = array('url' => $scripturl . '?action=admin;area=packages;sa=browse', 'name' => $context['uninstalling'] ? $txt['uninstall'] : $txt['extracting']); $context['page_title'] .= ' - ' . ($context['uninstalling'] ? $txt['uninstall'] : $txt['extracting']); $context['sub_template'] = 'extract_package'; if (!file_exists($boarddir . '/Packages/' . $context['filename'])) { fatal_lang_error('package_no_file', false); } // Load up the package FTP information? create_chmod_control(array(), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=' . $_REQUEST['sa'] . ';package=' . $_REQUEST['package'])); // Make sure temp directory exists and is empty! if (file_exists($boarddir . '/Packages/temp')) { deltree($boarddir . '/Packages/temp', false); } else { mktree($boarddir . '/Packages/temp', 0777); } // Let the unpacker do the work. if (is_file($boarddir . '/Packages/' . $context['filename'])) { $context['extracted_files'] = read_tgz_file($boarddir . '/Packages/' . $context['filename'], $boarddir . '/Packages/temp'); if (!file_exists($boarddir . '/Packages/temp/package-info.xml')) { foreach ($context['extracted_files'] as $file) { if (basename($file['filename']) == 'package-info.xml') { $context['base_path'] = dirname($file['filename']) . '/'; break; } } } if (!isset($context['base_path'])) { $context['base_path'] = ''; } } elseif (is_dir($boarddir . '/Packages/' . $context['filename'])) { copytree($boarddir . '/Packages/' . $context['filename'], $boarddir . '/Packages/temp'); $context['extracted_files'] = listtree($boarddir . '/Packages/temp'); $context['base_path'] = ''; } else { fatal_lang_error('no_access', false); } // Are we installing this into any custom themes? $custom_themes = array(1); $known_themes = explode(',', $modSettings['knownThemes']); if (!empty($_POST['custom_theme'])) { foreach ($_POST['custom_theme'] as $tid) { if (in_array($tid, $known_themes)) { $custom_themes[] = (int) $tid; } } } // Now load up the paths of the themes that we need to know about. $request = smf_db_query(' SELECT id_theme, variable, value FROM {db_prefix}themes WHERE id_theme IN ({array_int:custom_themes}) AND variable IN ({string:name}, {string:theme_dir})', array('custom_themes' => $custom_themes, 'name' => 'name', 'theme_dir' => 'theme_dir')); $theme_paths = array(); $themes_installed = array(1); while ($row = mysql_fetch_assoc($request)) { $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; } mysql_free_result($request); // Are there any theme copying that we want to take place? $context['theme_copies'] = array('require-file' => array(), 'require-dir' => array()); if (!empty($_POST['theme_changes'])) { foreach ($_POST['theme_changes'] as $change) { if (empty($change)) { continue; } $theme_data = unserialize(base64_decode($change)); if (empty($theme_data['type'])) { continue; } $themes_installed[] = $theme_data['id']; $context['theme_copies'][$theme_data['type']][$theme_data['orig']][] = $theme_data['future']; } } // Get the package info... $packageInfo = getPackageInfo($context['filename']); if (!is_array($packageInfo)) { fatal_lang_error($packageInfo); } $packageInfo['filename'] = $context['filename']; // Set the type of extraction... $context['extract_type'] = isset($packageInfo['type']) ? $packageInfo['type'] : 'modification'; // Create a backup file to roll back to! (but if they do this more than once, don't run it a zillion times.) if (!empty($modSettings['package_make_backups']) && (!isset($_SESSION['last_backup_for']) || $_SESSION['last_backup_for'] != $context['filename'] . ($context['uninstalling'] ? '$$' : '$'))) { $_SESSION['last_backup_for'] = $context['filename'] . ($context['uninstalling'] ? '$$' : '$'); // !!! Internationalize this? package_create_backup(($context['uninstalling'] ? 'backup_' : 'before_') . strtok($context['filename'], '.')); } // The mod isn't installed.... unless proven otherwise. $context['is_installed'] = false; // Is it actually installed? $request = smf_db_query(' SELECT version, themes_installed, db_changes FROM {db_prefix}log_packages WHERE package_id = {string:current_package} AND install_state != {int:not_installed} ORDER BY time_installed DESC LIMIT 1', array('not_installed' => 0, 'current_package' => $packageInfo['id'])); while ($row = mysql_fetch_assoc($request)) { $old_themes = explode(',', $row['themes_installed']); $old_version = $row['version']; $db_changes = empty($row['db_changes']) ? array() : unserialize($row['db_changes']); } mysql_free_result($request); // Wait, it's not installed yet! // !!! TODO: Replace with a better error message! if (!isset($old_version) && $context['uninstalling']) { deltree($boarddir . '/Packages/temp'); fatal_error('Hacker?', false); } elseif ($context['uninstalling']) { $install_log = parsePackageInfo($packageInfo['xml'], false, 'uninstall'); // Gadzooks! There's no uninstaller at all!? if (empty($install_log)) { fatal_lang_error('package_uninstall_cannot', false); } // They can only uninstall from what it was originally installed into. foreach ($theme_paths as $id => $data) { if ($id != 1 && !in_array($id, $old_themes)) { unset($theme_paths[$id]); } } } elseif (isset($old_version) && $old_version != $packageInfo['version']) { // Look for an upgrade... $install_log = parsePackageInfo($packageInfo['xml'], false, 'upgrade', $old_version); // There was no upgrade.... if (empty($install_log)) { $context['is_installed'] = true; } else { // Upgrade previous themes only! foreach ($theme_paths as $id => $data) { if ($id != 1 && !in_array($id, $old_themes)) { unset($theme_paths[$id]); } } } } elseif (isset($old_version) && $old_version == $packageInfo['version']) { $context['is_installed'] = true; } if (!isset($old_version) || $context['is_installed']) { $install_log = parsePackageInfo($packageInfo['xml'], false, 'install'); } $context['install_finished'] = false; // !!! TODO: Make a log of any errors that occurred and output them? if (!empty($install_log)) { $failed_steps = array(); $failed_count = 0; foreach ($install_log as $action) { $failed_count++; if ($action['type'] == 'modification' && !empty($action['filename'])) { if ($action['boardmod']) { $mod_actions = parseBoardMod(file_get_contents($boarddir . '/Packages/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths); } else { $mod_actions = parseModification(file_get_contents($boarddir . '/Packages/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths); } // Any errors worth noting? foreach ($mod_actions as $key => $action) { if ($action['type'] == 'failure') { $failed_steps[] = array('file' => $action['filename'], 'large_step' => $failed_count, 'sub_step' => $key, 'theme' => 1); } // Gather the themes we installed into. if (!empty($action['is_custom'])) { $themes_installed[] = $action['is_custom']; } } } elseif ($action['type'] == 'code' && !empty($action['filename'])) { // This is just here as reference for what is available. global $txt, $boarddir, $sourcedir, $modSettings, $context, $settings, $forum_version, $smcFunc; // Now include the file and be done with it ;). require $boarddir . '/Packages/temp/' . $context['base_path'] . $action['filename']; } elseif ($action['type'] == 'database' && !empty($action['filename']) && (!$context['uninstalling'] || !empty($_POST['do_db_changes']))) { // These can also be there for database changes. global $txt, $boarddir, $sourcedir, $modSettings, $context, $settings, $forum_version, $smcFunc; global $db_package_log; // We'll likely want the package specific database functionality! db_extend('packages'); // Let the file work its magic ;) require $boarddir . '/Packages/temp/' . $context['base_path'] . $action['filename']; } elseif ($action['type'] == 'redirect' && !empty($action['redirect_url'])) { $context['redirect_url'] = $action['redirect_url']; $context['redirect_text'] = !empty($action['filename']) && file_exists($boarddir . '/Packages/temp/' . $context['base_path'] . $action['filename']) ? file_get_contents($boarddir . '/Packages/temp/' . $context['base_path'] . $action['filename']) : ($context['uninstalling'] ? $txt['package_uninstall_done'] : $txt['package_installed_done']); $context['redirect_timeout'] = $action['redirect_timeout']; // Parse out a couple of common urls. $urls = array('$boardurl' => $boardurl, '$scripturl' => $scripturl, '$session_var' => $context['session_var'], '$session_id' => $context['session_id']); $context['redirect_url'] = strtr($context['redirect_url'], $urls); } } package_flush_cache(); // First, ensure this change doesn't get removed by putting a stake in the ground (So to speak). package_put_contents($boarddir . '/Packages/installed.list', time()); // See if this is already installed, and change it's state as required. $request = smf_db_query(' SELECT package_id, install_state, db_changes FROM {db_prefix}log_packages WHERE install_state != {int:not_installed} AND package_id = {string:current_package} ' . ($context['install_id'] ? ' AND id_install = {int:install_id} ' : '') . ' ORDER BY time_installed DESC LIMIT 1', array('not_installed' => 0, 'install_id' => $context['install_id'], 'current_package' => $packageInfo['id'])); $is_upgrade = false; while ($row = mysql_fetch_assoc($request)) { // Uninstalling? if ($context['uninstalling']) { smf_db_query(' UPDATE {db_prefix}log_packages SET install_state = {int:not_installed}, member_removed = {string:member_name}, id_member_removed = {int:current_member}, time_removed = {int:current_time} WHERE package_id = {string:package_id}', array('current_member' => $user_info['id'], 'not_installed' => 0, 'current_time' => time(), 'package_id' => $row['package_id'], 'member_name' => $user_info['name'])); } else { $is_upgrade = true; $old_db_changes = empty($row['db_changes']) ? array() : unserialize($row['db_changes']); } } // Assuming we're not uninstalling, add the entry. if (!$context['uninstalling']) { // Any db changes from older version? if (!empty($old_db_changes)) { $db_package_log = empty($db_package_log) ? $old_db_changes : array_merge($old_db_changes, $db_package_log); } // If there are some database changes we might want to remove then filter them out. if (!empty($db_package_log)) { // We're really just checking for entries which are create table AND add columns (etc). $tables = array(); function sort_table_first($a, $b) { if ($a[0] == $b[0]) { return 0; } return $a[0] == 'remove_table' ? -1 : 1; } usort($db_package_log, 'sort_table_first'); foreach ($db_package_log as $k => $log) { if ($log[0] == 'remove_table') { $tables[] = $log[1]; } elseif (in_array($log[1], $tables)) { unset($db_package_log[$k]); } } $db_changes = serialize($db_package_log); } else { $db_changes = ''; } // What themes did we actually install? $themes_installed = array_unique($themes_installed); $themes_installed = implode(',', $themes_installed); // What failed steps? $failed_step_insert = serialize($failed_steps); smf_db_insert('', '{db_prefix}log_packages', array('filename' => 'string', 'name' => 'string', 'package_id' => 'string', 'version' => 'string', 'id_member_installed' => 'int', 'member_installed' => 'string', 'time_installed' => 'int', 'install_state' => 'int', 'failed_steps' => 'string', 'themes_installed' => 'string', 'member_removed' => 'int', 'db_changes' => 'string'), array($packageInfo['filename'], $packageInfo['name'], $packageInfo['id'], $packageInfo['version'], $user_info['id'], $user_info['name'], time(), $is_upgrade ? 2 : 1, $failed_step_insert, $themes_installed, 0, $db_changes), array('id_install')); } mysql_free_result($request); $context['install_finished'] = true; } // If there's database changes - and they want them removed - let's do it last! if (!empty($db_changes) && !empty($_POST['do_db_changes'])) { // We're gonna be needing the package db functions! db_extend('packages'); foreach ($db_changes as $change) { if ($change[0] == 'remove_table' && isset($change[1])) { smf_db_drop_table($change[1]); } elseif ($change[0] == 'remove_column' && isset($change[2])) { smf_db_remove_column($change[1], $change[2]); } elseif ($change[0] == 'remove_index' && isset($change[2])) { smf_db_remove_index($change[1], $change[2]); } } } // Clean house... get rid of the evidence ;). if (file_exists($boarddir . '/Packages/temp')) { deltree($boarddir . '/Packages/temp'); } // Log what we just did. logAction($context['uninstalling'] ? 'uninstall_package' : (!empty($is_upgrade) ? 'upgrade_package' : 'install_package'), array('package' => commonAPI::htmlspecialchars($packageInfo['name']), 'version' => commonAPI::htmlspecialchars($packageInfo['version'])), 'admin'); // Just in case, let's clear the whole cache to avoid anything going up the swanny. clean_cache(); // Restore file permissions? create_chmod_control(array(), array(), true); }
function ShopUserGroup() { global $smcFunc, $boarddir, $context, $txt; // If form wasn't submitted yet... if (!isset($_GET['step']) || $_GET['step'] == 1) { // Start with an empty list $context['shop_usergroups'] = array(); // Get all non post-based membergroups $result = $smcFunc['db_query']('', "\n\t\t\tSELECT id_group, group_name\n\t\t\tFROM {db_prefix}membergroups\n\t\t\tWHERE min_posts = -1", array()); // For each membergroup, add it to the list while ($row = $smcFunc['db_fetch_assoc']($result)) { $context['shop_usergroups'][] = array('id' => $row['id_group'], 'groupName' => $row['group_name']); } $smcFunc['db_free_result']($result); } else { // Adding, or subtracting? $action = $_POST['m_action'] == 'sub' ? '-' : '+'; // Make sure inputs were numeric $_POST['usergroup'] = (int) $_POST['usergroup']; $_POST['value'] = (double) $_POST['value']; // Do it! $smcFunc['db_query']('', "\n\t\t\tUPDATE {db_prefix}members\n\t\t\tSET money = money {raw:action} {int:value}\n\t\t\tWHERE id_group = {int:group}", array('action' => $action, 'value' => $_POST['value'], 'group' => $_POST['usergroup'])); clean_cache(); } // We're using the "usergroup" template $context['sub_template'] = 'usergroup'; $context['page_title'] = $txt['shop'] . ' - ' . $txt['shop_admin_usergroup']; // Load the actual template loadTemplate('ShopAdmin'); }
/** * This function does daily cleaning up: * * - decrements warning levels if it's enabled * - consolidate spider statistics * - fix MySQL version * - regenerate Diffie-Hellman keys for OpenID * - remove obsolete login history logs */ public function daily_maintenance() { global $modSettings, $db_type; $db = database(); // First clean out the cache. clean_cache('data'); // If warning decrement is enabled and we have people who have not had a new warning in 24 hours, lower their warning level. list(, , $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']); if ($modSettings['warning_decrement']) { // Find every member who has a warning level... $request = $db->query('', ' SELECT id_member, warning FROM {db_prefix}members WHERE warning > {int:no_warning}', array('no_warning' => 0)); $members = array(); while ($row = $db->fetch_assoc($request)) { $members[$row['id_member']] = $row['warning']; } $db->free_result($request); // Have some members to check? if (!empty($members)) { // Find out when they were last warned. $request = $db->query('', ' SELECT id_recipient, MAX(log_time) AS last_warning FROM {db_prefix}log_comments WHERE id_recipient IN ({array_int:member_list}) AND comment_type = {string:warning} GROUP BY id_recipient', array('member_list' => array_keys($members), 'warning' => 'warning')); $member_changes = array(); while ($row = $db->fetch_assoc($request)) { // More than 24 hours ago? if ($row['last_warning'] <= time() - 86400) { $member_changes[] = array('id' => $row['id_recipient'], 'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0); } } $db->free_result($request); // Have some members to change? if (!empty($member_changes)) { foreach ($member_changes as $change) { updateMemberData($change['id'], array('warning' => $change['warning'])); } } } } // Do any spider stuff. if (!empty($modSettings['spider_mode']) && $modSettings['spider_mode'] > 1) { // We'll need this. require_once SUBSDIR . '/SearchEngines.subs.php'; consolidateSpiderStats(); } // Check the database version - for some buggy MySQL version. $server_version = $db->db_server_info(); if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { updateSettings(array('db_mysql_group_by_fix' => '1')); } elseif (!empty($modSettings['db_mysql_group_by_fix'])) { $db->query('', ' DELETE FROM {db_prefix}settings WHERE variable = {string:mysql_fix}', array('mysql_fix' => 'db_mysql_group_by_fix')); } // Regenerate the Diffie-Hellman keys if OpenID is enabled. if (!empty($modSettings['enableOpenID'])) { require_once SUBSDIR . '/OpenID.subs.php'; $openID = new OpenID(); $openID->setup_DH(true); } elseif (!empty($modSettings['dh_keys'])) { $db->query('', ' DELETE FROM {db_prefix}settings WHERE variable = {string:dh_keys}', array('dh_keys' => 'dh_keys')); } // Clean up some old login history information. $db->query('', ' DELETE FROM {db_prefix}member_logins WHERE time > {int:oldLogins}', array('oldLogins' => !empty($modSettings['loginHistoryDays']) ? 60 * 60 * $modSettings['loginHistoryDays'] : 108000)); // Log we've done it... return true; }
function CheckQuotaSQL_cache($MDKEY) { clean_cache(); $CacheTime = round($GLOBALS["PARAMS"]["CACHE_TIME"] / 60); if ($CacheTime == 0) { $CacheTime = 6; $GLOBALS["PARAMS"]["CACHE_TIME"] = $CacheTime * 60; } if (!isset($GLOBALS["SQLCACHE"][$MDKEY])) { return 0; } $data1 = $GLOBALS["SQLCACHE"][$MDKEY]["TIME"]; $data2 = time(); $difference = $data2 - $data1; $mins = round($difference / 60); if ($GLOBALS["DEBUG_LEVEL"] > 1) { WLOG("CheckQuotaSQL_cache() -> {$mins}Mn/{$CacheTime}Mn return {$GLOBALS["SQLCACHE"][$MDKEY]["VALUE"]}MB"); } if ($mins < $CacheTime) { return $GLOBALS["SQLCACHE"][$MDKEY]["VALUE"]; } }
function ModifyLanguage() { global $settings, $context, $smcFunc, $txt, $modSettings, $boarddir, $sourcedir, $language; loadLanguage('ManageSettings'); // Select the languages tab. $context['menu_data_' . $context['admin_menu_id']]['current_subsection'] = 'edit'; $context['page_title'] = $txt['edit_languages']; $context['sub_template'] = 'modify_language_entries'; $context['lang_id'] = $_GET['lid']; list($theme_id, $file_id) = empty($_REQUEST['tfid']) || strpos($_REQUEST['tfid'], '+') === false ? array(1, '') : explode('+', $_REQUEST['tfid']); // Clean the ID - just in case. preg_match('~([A-Za-z0-9_-]+)~', $context['lang_id'], $matches); $context['lang_id'] = $matches[1]; // Get all the theme data. $request = $smcFunc['db_query']('', ' SELECT id_theme, variable, value FROM {db_prefix}themes WHERE id_theme != {int:default_theme} AND id_member = {int:no_member} AND variable IN ({string:name}, {string:theme_dir})', array('default_theme' => 1, 'no_member' => 0, 'name' => 'name', 'theme_dir' => 'theme_dir')); $themes = array(1 => array('name' => $txt['dvc_default'], 'theme_dir' => $settings['default_theme_dir'])); while ($row = $smcFunc['db_fetch_assoc']($request)) { $themes[$row['id_theme']][$row['variable']] = $row['value']; } $smcFunc['db_free_result']($request); // This will be where we look $lang_dirs = array(); // Check we have themes with a path and a name - just in case - and add the path. foreach ($themes as $id => $data) { if (count($data) != 2) { unset($themes[$id]); } elseif (is_dir($data['theme_dir'] . '/languages')) { $lang_dirs[$id] = $data['theme_dir'] . '/languages'; } // How about image directories? if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id'])) { $images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id']; } } $current_file = $file_id ? $lang_dirs[$theme_id] . '/' . $file_id . '.' . $context['lang_id'] . '.php' : ''; // Now for every theme get all the files and stick them in context! $context['possible_files'] = array(); foreach ($lang_dirs as $theme => $theme_dir) { // Open it up. $dir = dir($theme_dir); while ($entry = $dir->read()) { // We're only after the files for this language. if (preg_match('~^([A-Za-z]+)\\.' . $context['lang_id'] . '\\.php$~', $entry, $matches) == 0) { continue; } //!!! Temp! if ($matches[1] == 'EmailTemplates') { continue; } if (!isset($context['possible_files'][$theme])) { $context['possible_files'][$theme] = array('id' => $theme, 'name' => $themes[$theme]['name'], 'files' => array()); } $context['possible_files'][$theme]['files'][] = array('id' => $matches[1], 'name' => isset($txt['lang_file_desc_' . $matches[1]]) ? $txt['lang_file_desc_' . $matches[1]] : $matches[1], 'selected' => $theme_id == $theme && $file_id == $matches[1]); } $dir->close(); } // We no longer wish to speak this language. if (!empty($_POST['delete_main']) && $context['lang_id'] != 'english') { checkSession(); // !!! Todo: FTP Controls? require_once $sourcedir . '/Subs-Package.php'; // First, Make a backup? if (!empty($modSettings['package_make_backups']) && (!isset($_SESSION['last_backup_for']) || $_SESSION['last_backup_for'] != $context['lang_id'] . '$$$')) { $_SESSION['last_backup_for'] = $context['lang_id'] . '$$$'; package_create_backup('backup_lang_' . $context['lang_id']); } // Second, loop through the array to remove the files. foreach ($lang_dirs as $curPath) { foreach ($context['possible_files'][1]['files'] as $lang) { if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php')) { unlink($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php'); } } // Check for the email template. if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php')) { unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php'); } } // Third, the agreement file. if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt')) { unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt'); } // Fourth, a related images folder? foreach ($images_dirs as $curPath) { if (is_dir($curPath)) { deltree($curPath); } } // Fifth, update getLanguages() cache. if (!empty($modSettings['cache_enable'])) { cache_put_data('known_languages', null, !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); } // Sixth, if we deleted the default language, set us back to english? if ($context['lang_id'] == $language) { require_once $sourcedir . '/Subs-Admin.php'; $language = 'english'; updateSettingsFile(array('language' => '\'' . $language . '\'')); } // Seventh, get out of here. redirectexit('action=admin;area=languages;sa=edit;' . $context['session_var'] . '=' . $context['session_id']); } // Saving primary settings? $madeSave = false; if (!empty($_POST['save_main']) && !$current_file) { checkSession(); // Read in the current file. $current_data = implode('', file($settings['default_theme_dir'] . '/languages/index.' . $context['lang_id'] . '.php')); // These are the replacements. old => new $replace_array = array('~\\$txt\\[\'lang_character_set\'\\]\\s=\\s(\'|")[^\\r\\n]+~' => '$txt[\'lang_character_set\'] = \'' . addslashes($_POST['character_set']) . '\';', '~\\$txt\\[\'lang_locale\'\\]\\s=\\s(\'|")[^\\r\\n]+~' => '$txt[\'lang_locale\'] = \'' . addslashes($_POST['locale']) . '\';', '~\\$txt\\[\'lang_dictionary\'\\]\\s=\\s(\'|")[^\\r\\n]+~' => '$txt[\'lang_dictionary\'] = \'' . addslashes($_POST['dictionary']) . '\';', '~\\$txt\\[\'lang_spelling\'\\]\\s=\\s(\'|")[^\\r\\n]+~' => '$txt[\'lang_spelling\'] = \'' . addslashes($_POST['spelling']) . '\';', '~\\$txt\\[\'lang_rtl\'\\]\\s=\\s[A-Za-z0-9]+;~' => '$txt[\'lang_rtl\'] = ' . (!empty($_POST['rtl']) ? 'true' : 'false') . ';'); $current_data = preg_replace(array_keys($replace_array), array_values($replace_array), $current_data); $fp = fopen($settings['default_theme_dir'] . '/languages/index.' . $context['lang_id'] . '.php', 'w+'); fwrite($fp, $current_data); fclose($fp); $madeSave = true; } // Quickly load index language entries. $old_txt = $txt; require $settings['default_theme_dir'] . '/languages/index.' . $context['lang_id'] . '.php'; $context['lang_file_not_writable_message'] = is_writable($settings['default_theme_dir'] . '/languages/index.' . $context['lang_id'] . '.php') ? '' : sprintf($txt['lang_file_not_writable'], $settings['default_theme_dir'] . '/languages/index.' . $context['lang_id'] . '.php'); // Setup the primary settings context. $context['primary_settings'] = array('name' => $smcFunc['ucwords'](strtr($context['lang_id'], array('_' => ' ', '-utf8' => ''))), 'character_set' => $txt['lang_character_set'], 'locale' => $txt['lang_locale'], 'dictionary' => $txt['lang_dictionary'], 'spelling' => $txt['lang_spelling'], 'rtl' => $txt['lang_rtl']); // Restore normal service. $txt = $old_txt; // Are we saving? $save_strings = array(); if (isset($_POST['save_entries']) && !empty($_POST['entry'])) { checkSession(); // Clean each entry! foreach ($_POST['entry'] as $k => $v) { // Only try to save if it's changed! if ($_POST['entry'][$k] != $_POST['comp'][$k]) { $save_strings[$k] = cleanLangString($v, false); } } } // If we are editing a file work away at that. if ($current_file) { $context['entries_not_writable_message'] = is_writable($current_file) ? '' : sprintf($txt['lang_entries_not_writable'], $current_file); $entries = array(); // We can't just require it I'm afraid - otherwise we pass in all kinds of variables! $multiline_cache = ''; foreach (file($current_file) as $line) { // Got a new entry? if ($line[0] == '$' && !empty($multiline_cache)) { preg_match('~\\$(helptxt|txt)\\[\'(.+)\'\\]\\s=\\s(.+);~', strtr($multiline_cache, array("\n" => '', "\t" => '')), $matches); if (!empty($matches[3])) { $entries[$matches[2]] = array('type' => $matches[1], 'full' => $matches[0], 'entry' => $matches[3]); $multiline_cache = ''; } } $multiline_cache .= $line . "\n"; } // Last entry to add? if ($multiline_cache) { preg_match('~\\$(helptxt|txt)\\[\'(.+)\'\\]\\s=\\s(.+);~', strtr($multiline_cache, array("\n" => '', "\t" => '')), $matches); if (!empty($matches[3])) { $entries[$matches[2]] = array('type' => $matches[1], 'full' => $matches[0], 'entry' => $matches[3]); } } // These are the entries we can definitely save. $final_saves = array(); $context['file_entries'] = array(); foreach ($entries as $entryKey => $entryValue) { // Ignore some things we set separately. $ignore_files = array('lang_character_set', 'lang_locale', 'lang_dictionary', 'lang_spelling', 'lang_rtl'); if (in_array($entryKey, $ignore_files)) { continue; } // These are arrays that need breaking out. $arrays = array('days', 'days_short', 'months', 'months_titles', 'months_short'); if (in_array($entryKey, $arrays)) { // Get off the first bits. $entryValue['entry'] = substr($entryValue['entry'], strpos($entryValue['entry'], '(') + 1, strrpos($entryValue['entry'], ')') - strpos($entryValue['entry'], '(')); $entryValue['entry'] = explode(',', strtr($entryValue['entry'], array(' ' => ''))); // Now create an entry for each item. $cur_index = 0; $save_cache = array('enabled' => false, 'entries' => array()); foreach ($entryValue['entry'] as $id => $subValue) { // Is this a new index? if (preg_match('~^(\\d+)~', $subValue, $matches)) { $cur_index = $matches[1]; $subValue = substr($subValue, strpos($subValue, '\'')); } // Clean up some bits. $subValue = strtr($subValue, array('"' => '', '\'' => '', ')' => '')); // Can we save? if (isset($save_strings[$entryKey . '-+- ' . $cur_index])) { $save_cache['entries'][$cur_index] = strtr($save_strings[$entryKey . '-+- ' . $cur_index], array('\'' => '')); $save_cache['enabled'] = true; } else { $save_cache['entries'][$cur_index] = $subValue; } $context['file_entries'][] = array('key' => $entryKey . '-+- ' . $cur_index, 'value' => $subValue, 'rows' => 1); $cur_index++; } // Do we need to save? if ($save_cache['enabled']) { // Format the string, checking the indexes first. $items = array(); $cur_index = 0; foreach ($save_cache['entries'] as $k2 => $v2) { // Manually show the custom index. if ($k2 != $cur_index) { $items[] = $k2 . ' => \'' . $v2 . '\''; $cur_index = $k2; } else { $items[] = '\'' . $v2 . '\''; } $cur_index++; } // Now create the string! $final_saves[$entryKey] = array('find' => $entryValue['full'], 'replace' => '$' . $entryValue['type'] . '[\'' . $entryKey . '\'] = array(' . implode(', ', $items) . ');'); } } else { // Saving? if (isset($save_strings[$entryKey]) && $save_strings[$entryKey] != $entryValue['entry']) { // !!! Fix this properly. if ($save_strings[$entryKey] == '') { $save_strings[$entryKey] = '\'\''; } // Set the new value. $entryValue['entry'] = $save_strings[$entryKey]; // And we know what to save now! $final_saves[$entryKey] = array('find' => $entryValue['full'], 'replace' => '$' . $entryValue['type'] . '[\'' . $entryKey . '\'] = ' . $save_strings[$entryKey] . ';'); } $editing_string = cleanLangString($entryValue['entry'], true); $context['file_entries'][] = array('key' => $entryKey, 'value' => $editing_string, 'rows' => (int) (strlen($editing_string) / 38) + substr_count($editing_string, "\n") + 1); } } // Any saves to make? if (!empty($final_saves)) { checkSession(); $file_contents = implode('', file($current_file)); foreach ($final_saves as $save) { $file_contents = strtr($file_contents, array($save['find'] => $save['replace'])); } // Save the actual changes. $fp = fopen($current_file, 'w+'); fwrite($fp, $file_contents); fclose($fp); $madeSave = true; } // Another restore. $txt = $old_txt; } // If we saved, redirect. if ($madeSave) { clean_cache('lang'); redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id']); } }
function shd_maint_clean_cache() { global $context; clean_cache(); // Normally, we'd update $context['continue_post_data'] to indicate our next port of call. But here, we don't have to. redirectexit('action=admin;area=helpdesk_maint;sa=findrepair;done;' . $context['session_var'] . '=' . $context['session_id']); }
/** * Generates a list of integration hooks for display * * - Accessed through ?action=admin;area=maintain;sa=hooks; * - Allows for removal or disabing of selected hooks */ public function action_hooks() { global $scripturl, $context, $txt, $modSettings, $settings; require_once SUBSDIR . '/AddonSettings.subs.php'; $context['filter_url'] = ''; $context['current_filter'] = ''; // Get the list of the current system hooks, filter them if needed $currentHooks = get_integration_hooks(); if (isset($_GET['filter']) && in_array($_GET['filter'], array_keys($currentHooks))) { $context['filter_url'] = ';filter=' . $_GET['filter']; $context['current_filter'] = $_GET['filter']; } if (!empty($modSettings['handlinghooks_enabled'])) { if (!empty($_REQUEST['do']) && isset($_REQUEST['hook']) && isset($_REQUEST['function'])) { checkSession('request'); validateToken('admin-hook', 'request'); if ($_REQUEST['do'] == 'remove') { remove_integration_function($_REQUEST['hook'], urldecode($_REQUEST['function'])); } else { if ($_REQUEST['do'] == 'disable') { // It's a hack I know...but I'm way too lazy!!! $function_remove = $_REQUEST['function']; $function_add = $_REQUEST['function'] . ']'; } else { $function_remove = $_REQUEST['function'] . ']'; $function_add = $_REQUEST['function']; } $file = !empty($_REQUEST['includedfile']) ? urldecode($_REQUEST['includedfile']) : ''; remove_integration_function($_REQUEST['hook'], $function_remove, $file); add_integration_function($_REQUEST['hook'], $function_add, $file); // Clean the cache. require_once SUBSDIR . '/Cache.subs.php'; clean_cache(); } redirectexit('action=admin;area=maintain;sa=hooks' . $context['filter_url']); } } $list_options = array('id' => 'list_integration_hooks', 'title' => $txt['maintain_sub_hooks_list'], 'items_per_page' => 20, 'base_href' => $scripturl . '?action=admin;area=maintain;sa=hooks' . $context['filter_url'] . ';' . $context['session_var'] . '=' . $context['session_id'], 'default_sort_col' => 'hook_name', 'get_items' => array('function' => array($this, 'list_getIntegrationHooks')), 'get_count' => array('function' => array($this, 'list_getIntegrationHooksCount')), 'no_items_label' => $txt['hooks_no_hooks'], 'columns' => array('hook_name' => array('header' => array('value' => $txt['hooks_field_hook_name']), 'data' => array('db' => 'hook_name'), 'sort' => array('default' => 'hook_name', 'reverse' => 'hook_name DESC')), 'function_name' => array('header' => array('value' => $txt['hooks_field_function_name']), 'data' => array('function' => create_function('$data', ' global $txt; if (!empty($data[\'included_file\'])) return $txt[\'hooks_field_function\'] . \': \' . $data[\'real_function\'] . \'<br />\' . $txt[\'hooks_field_included_file\'] . \': \' . $data[\'included_file\']; else return $data[\'real_function\']; ')), 'sort' => array('default' => 'function_name', 'reverse' => 'function_name DESC')), 'file_name' => array('header' => array('value' => $txt['hooks_field_file_name']), 'data' => array('db' => 'file_name'), 'sort' => array('default' => 'file_name', 'reverse' => 'file_name DESC')), 'status' => array('header' => array('value' => $txt['hooks_field_hook_exists'], 'class' => 'nowrap'), 'data' => array('function' => create_function('$data', ' global $txt, $settings, $scripturl, $context; $change_status = array(\'before\' => \'\', \'after\' => \'\'); if ($data[\'can_be_disabled\'] && $data[\'status\'] != \'deny\') { $change_status[\'before\'] = \'<a href="\' . $scripturl . \'?action=admin;area=maintain;sa=hooks;do=\' . ($data[\'enabled\'] ? \'disable\' : \'enable\') . \';hook=\' . $data[\'hook_name\'] . \';function=\' . $data[\'real_function\'] . (!empty($data[\'included_file\']) ? \';includedfile=\' . urlencode($data[\'included_file\']) : \'\') . $context[\'filter_url\'] . \';\' . $context[\'admin-hook_token_var\'] . \'=\' . $context[\'admin-hook_token\'] . \';\' . $context[\'session_var\'] . \'=\' . $context[\'session_id\'] . \'" onclick="return confirm(\' . javaScriptEscape($txt[\'quickmod_confirm\']) . \');">\'; $change_status[\'after\'] = \'</a>\'; } return $change_status[\'before\'] . \'<img src="\' . $settings[\'images_url\'] . \'/admin/post_moderation_\' . $data[\'status\'] . \'.png" alt="\' . $data[\'img_text\'] . \'" title="\' . $data[\'img_text\'] . \'" />\' . $change_status[\'after\']; '), 'class' => 'centertext'), 'sort' => array('default' => 'status', 'reverse' => 'status DESC'))), 'additional_rows' => array(array('position' => 'after_title', 'value' => $txt['hooks_disable_instructions'] . '<br /> ' . $txt['hooks_disable_legend'] . ': <ul> <li> <img src="' . $settings['images_url'] . '/admin/post_moderation_allow.png" alt="' . $txt['hooks_active'] . '" title="' . $txt['hooks_active'] . '" /> ' . $txt['hooks_disable_legend_exists'] . ' </li> <li> <img src="' . $settings['images_url'] . '/admin/post_moderation_moderate.png" alt="' . $txt['hooks_disabled'] . '" title="' . $txt['hooks_disabled'] . '" /> ' . $txt['hooks_disable_legend_disabled'] . ' </li> <li> <img src="' . $settings['images_url'] . '/admin/post_moderation_deny.png" alt="' . $txt['hooks_missing'] . '" title="' . $txt['hooks_missing'] . '" /> ' . $txt['hooks_disable_legend_missing'] . ' </li> </ul>'))); if (!empty($modSettings['handlinghooks_enabled'])) { createToken('admin-hook', 'request'); $list_options['columns']['remove'] = array('header' => array('value' => $txt['hooks_button_remove'], 'style' => 'width:3%'), 'data' => array('function' => create_function('$data', ' global $txt, $settings, $scripturl, $context; if (!$data[\'hook_exists\']) return \' <a href="\' . $scripturl . \'?action=admin;area=maintain;sa=hooks;do=remove;hook=\' . $data[\'hook_name\'] . \';function=\' . urlencode($data[\'function_name\']) . $context[\'filter_url\'] . \';\' . $context[\'admin-hook_token_var\'] . \'=\' . $context[\'admin-hook_token\'] . \';\' . $context[\'session_var\'] . \'=\' . $context[\'session_id\'] . \'" onclick="return confirm(\' . javaScriptEscape($txt[\'quickmod_confirm\']) . \');"> <img src="\' . $settings[\'images_url\'] . \'/icons/quick_remove.png" alt="\' . $txt[\'hooks_button_remove\'] . \'" title="\' . $txt[\'hooks_button_remove\'] . \'" /> </a>\'; '), 'class' => 'centertext')); $list_options['form'] = array('href' => $scripturl . '?action=admin;area=maintain;sa=hooks' . $context['filter_url'] . ';' . $context['session_var'] . '=' . $context['session_id'], 'name' => 'list_integration_hooks'); } require_once SUBSDIR . '/GenericList.class.php'; createList($list_options); $context['page_title'] = $txt['maintain_sub_hooks_list']; $context['sub_template'] = 'show_list'; $context['default_list'] = 'list_integration_hooks'; }
/** * Delete the damn thing! * Finalizes the upgrade * Updates maintenance mode to what it was before the upgrade started * Updates settings.php, sometimes even correctly * Flushes the cache so there is a clean start * Runs a scheduled fetch files so the install can be checked in the admin panel */ function action_deleteUpgrade() { global $command_line, $language, $upcontext, $forum_version, $user_info, $maintenance, $db_type; // Now it's nice to have some of the basic source files. if (!isset($_GET['ssi']) && !$command_line) { redirectLocation('&ssi=1'); } $upcontext['sub_template'] = 'upgrade_complete'; $upcontext['page_title'] = 'Upgrade Complete'; $endl = $command_line ? "\n" : '<br />' . "\n"; $changes = array('language' => '\'' . (substr($language, -4) == '.lng' ? substr($language, 0, -4) : $language) . '\'', 'db_error_send' => '1'); // Are we in maintenance mode? if (isset($upcontext['user']['main'])) { if ($command_line) { echo ' * '; } $upcontext['removed_maintenance'] = true; $changes['maintenance'] = $upcontext['user']['main']; } elseif (!empty($maintenance) && $maintenance == 2) { $changes['maintenance'] = 1; } // Wipe this out... $upcontext['user'] = array(); // @todo this is mad and needs to be looked at // Make a backup of Settings.php first as otherwise earlier changes are lost. copy(BOARDDIR . '/Settings.php', BOARDDIR . '/Settings_bak.php'); changeSettings($changes); // Now remove our marker $changes = array('upgradeData' => '#remove#'); changeSettings($changes); copy(BOARDDIR . '/Settings.php', BOARDDIR . '/Settings_bak.php'); // Clean any old cache files away. clean_cache(); // Can we delete the file? $upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__); // Now is the perfect time to fetch the ELK files. if ($command_line) { cli_scheduled_fetchFiles(); } else { // The variable is usually defined in index.php so lets just use the constant to do it for us. $forum_version = CURRENT_VERSION; // Now go get those files! require_once SUBSDIR . '/ScheduledTask.class.php'; $task = new Scheduled_Task(); $task->fetchFiles(); } // Log what we've done. if (empty($user_info['id'])) { $user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0; } // We need to log in the database $db = database(); // Log the action manually, so CLI still works. $db->insert('', '{db_prefix}log_actions', array('log_time' => 'int', 'id_log' => 'int', 'id_member' => 'int', 'ip' => 'string-16', 'action' => 'string', 'id_board' => 'int', 'id_topic' => 'int', 'id_msg' => 'int', 'extra' => 'string-65534'), array(time(), 3, $user_info['id'], $command_line ? '127.0.0.1' : $user_info['ip'], 'upgrade', 0, 0, 0, serialize(array('version' => $forum_version, 'member' => $user_info['id']))), array('id_action')); $user_info['id'] = 0; // Save the current database version. $server_version = $db->db_server_info(); if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { updateSettings(array('db_mysql_group_by_fix' => '1')); } // Set jquery to auto if its not already set if (!isset($modSettings['jquery_source'])) { updateSettings(array('jquery_source' => 'auto')); } if ($command_line) { echo $endl; echo 'Upgrade Complete!', $endl; echo 'Please delete this file as soon as possible for security reasons.', $endl; exit; } // Make sure it says we're done. $upcontext['overall_percent'] = 100; if (isset($upcontext['step_progress'])) { unset($upcontext['step_progress']); } $_GET['substep'] = 0; return false; }
/** * This is an overall control panel enabling/disabling lots of SMF's key feature components. * * @param $return_config */ function ModifyCoreFeatures($return_config = false) { global $txt, $scripturl, $context, $settings, $sc, $modSettings; /* This is an array of all the features that can be enabled/disabled - each option can have the following: title - Text title of this item (If standard string does not exist). desc - Description of this feature (If standard string does not exist). settings - Array of settings to change (For each name => value) on enable - reverse is done for disable. If > 1 will not change value if set. setting_callback- Function that returns an array of settings to save - takes one parameter which is value for this feature. save_callback - Function called on save, takes state as parameter. */ $core_features = array('cd' => array('url' => 'action=admin;area=managecalendar', 'settings' => array('cal_enabled' => 1)), 'cp' => array('url' => 'action=admin;area=featuresettings;sa=profile', 'save_callback' => create_function('$value', ' global $smcFunc; if (!$value) { $smcFunc[\'db_query\'](\'\', \' UPDATE {db_prefix}custom_fields SET active = 0\'); } '), 'setting_callback' => create_function('$value', ' if (!$value) return array( \'disabled_profile_fields\' => \'\', \'registration_fields\' => \'\', \'displayFields\' => \'\', ); else return array(); ')), 'dr' => array('url' => 'action=admin;area=managedrafts', 'settings' => array('drafts_enabled' => 1, 'drafts_post_enabled' => 2, 'drafts_pm_enabled' => 2, 'drafts_autosave_enabled' => 2, 'drafts_show_saved_enabled' => 2), 'setting_callback' => create_function('$value', ' global $smcFunc, $sourcedir; // Set the correct disabled value for the scheduled task. $smcFunc[\'db_query\'](\'\', \' UPDATE {db_prefix}scheduled_tasks SET disabled = {int:disabled} WHERE task = {string:task}\', array( \'disabled\' => $value ? 0 : 1, \'task\' => \'remove_old_drafts\', ) ); ')), 'ih' => array('url' => 'action=admin;area=modsettings;sa=hooks', 'settings' => array('handlinghooks_enabled' => 1)), 'k' => array('url' => 'action=admin;area=featuresettings;sa=karma', 'settings' => array('karmaMode' => 2)), 'ml' => array('url' => 'action=admin;area=logs;sa=modlog', 'settings' => array('modlog_enabled' => 1)), 'pm' => array('url' => 'action=admin;area=permissions;sa=postmod', 'setting_callback' => create_function('$value', ' global $sourcedir; // Cant use warning post moderation if disabled! if (!$value) { require_once($sourcedir . \'/PostModeration.php\'); approveAllData(); return array(\'warning_moderate\' => 0); } else return array(); ')), 'ps' => array('url' => 'action=admin;area=paidsubscribe', 'settings' => array('paid_enabled' => 1), 'setting_callback' => create_function('$value', ' global $smcFunc, $sourcedir; // Set the correct disabled value for scheduled task. $smcFunc[\'db_query\'](\'\', \' UPDATE {db_prefix}scheduled_tasks SET disabled = {int:disabled} WHERE task = {string:task}\', array( \'disabled\' => $value ? 0 : 1, \'task\' => \'paid_subscriptions\', ) ); // Should we calculate next trigger? if ($value) { require_once($sourcedir . \'/ScheduledTasks.php\'); CalculateNextTrigger(\'paid_subscriptions\'); } ')), 'rg' => array('url' => 'action=admin;area=reports'), 'w' => array('url' => 'action=admin;area=securitysettings;sa=moderation', 'setting_callback' => create_function('$value', ' global $modSettings; list ($modSettings[\'warning_enable\'], $modSettings[\'user_limit\'], $modSettings[\'warning_decrement\']) = explode(\',\', $modSettings[\'warning_settings\']); $warning_settings = ($value ? 1 : 0) . \',\' . $modSettings[\'user_limit\'] . \',\' . $modSettings[\'warning_decrement\']; if (!$value) { $returnSettings = array( \'warning_watch\' => 0, \'warning_moderate\' => 0, \'warning_mute\' => 0, ); } elseif (empty($modSettings[\'warning_enable\']) && $value) { $returnSettings = array( \'warning_watch\' => 10, \'warning_moderate\' => 35, \'warning_mute\' => 60, ); } else $returnSettings = array(); $returnSettings[\'warning_settings\'] = $warning_settings; return $returnSettings; ')), 'sp' => array('url' => 'action=admin;area=sengines', 'settings' => array('spider_mode' => 1), 'setting_callback' => create_function('$value', ' // Turn off the spider group if disabling. if (!$value) return array(\'spider_group\' => 0, \'show_spider_online\' => 0); '), 'on_save' => create_function('', ' global $sourcedir, $modSettings; require_once($sourcedir . \'/ManageSearchEngines.php\'); recacheSpiderNames(); '))); // Anyone who would like to add a core feature? call_integration_hook('integrate_core_features', array(&$core_features)); // Are we getting info for the help section. if ($return_config) { $return_data = array(); foreach ($core_features as $id => $data) { $return_data[] = array('switch', isset($data['title']) ? $data['title'] : $txt['core_settings_item_' . $id]); } return $return_data; } loadGeneralSettingParameters(); // Are we saving? if (isset($_POST['save'])) { checkSession(); if (isset($_GET['xml'])) { $tokenValidation = validateToken('admin-core', 'post', false); if (empty($tokenValidation)) { return 'token_verify_fail'; } } else { validateToken('admin-core'); } $setting_changes = array('admin_features' => array()); // Cycle each feature and change things as required! foreach ($core_features as $id => $feature) { // Enabled? if (!empty($_POST['feature_' . $id])) { $setting_changes['admin_features'][] = $id; } // Setting values to change? if (isset($feature['settings'])) { foreach ($feature['settings'] as $key => $value) { if (empty($_POST['feature_' . $id]) || !empty($_POST['feature_' . $id]) && ($value < 2 || empty($modSettings[$key]))) { $setting_changes[$key] = !empty($_POST['feature_' . $id]) ? $value : !$value; } } } // Is there a call back for settings? if (isset($feature['setting_callback'])) { $returned_settings = $feature['setting_callback'](!empty($_POST['feature_' . $id])); if (!empty($returned_settings)) { $setting_changes = array_merge($setting_changes, $returned_settings); } } // Standard save callback? if (isset($feature['on_save'])) { $feature['on_save'](); } } // Make sure this one setting is a string! $setting_changes['admin_features'] = implode(',', $setting_changes['admin_features']); // Make any setting changes! updateSettings($setting_changes); // This is needed to let menus appear if cache > 2 clean_cache('data'); // Any post save things? foreach ($core_features as $id => $feature) { // Standard save callback? if (isset($feature['save_callback'])) { $feature['save_callback'](!empty($_POST['feature_' . $id])); } } if (!isset($_REQUEST['xml'])) { redirectexit('action=admin;area=corefeatures;' . $context['session_var'] . '=' . $context['session_id']); } } // Put them in context. $context['features'] = array(); foreach ($core_features as $id => $feature) { $context['features'][$id] = array('title' => isset($feature['title']) ? $feature['title'] : $txt['core_settings_item_' . $id], 'desc' => isset($feature['desc']) ? $feature['desc'] : $txt['core_settings_item_' . $id . '_desc'], 'enabled' => in_array($id, $context['admin_features']), 'state' => in_array($id, $context['admin_features']) ? 'on' : 'off', 'url' => !empty($feature['url']) ? $scripturl . '?' . $feature['url'] . ';' . $context['session_var'] . '=' . $context['session_id'] : '', 'image' => (file_exists($settings['theme_dir'] . '/images/admin/feature_' . $id . '.png') ? $settings['images_url'] : $settings['default_images_url']) . '/admin/feature_' . $id . '.png'); } // Are they a new user? $context['is_new_install'] = !isset($modSettings['admin_features']); $context['force_disable_tabs'] = $context['is_new_install']; // Don't show them this twice! if ($context['is_new_install']) { updateSettings(array('admin_features' => '')); } // sub_template is already generic_xml and the token is created somewhere else if (isset($_REQUEST['xml'])) { return; } $context['sub_template'] = 'core_features'; $context['page_title'] = $txt['core_settings_title']; // We love our tokens. createToken('admin-core'); }
/** * This is an overall control panel enabling/disabling lots of the forums key features. * * What it does: * - Uses internally an array of all the features that can be enabled/disabled. * - $core_features, each option can have the following: * - title - Text title of this item (If standard string does not exist). * - desc - Description of this feature (If standard string does not exist). * - settings - Array of settings to change (For each name => value) on enable * reverse is done for disable. If value > 1 will not change value if set. * - setting_callback - Function that returns an array of settings to save * takes one parameter which is value for this feature. * - save_callback - Function called on save, takes state as parameter. */ public function action_features() { global $txt, $scripturl, $context, $settings, $modSettings; require_once SUBSDIR . '/Admin.subs.php'; loadTemplate('CoreFeatures'); $core_features = $this->settings(); $this->loadGeneralSettingParameters(); // Are we saving? if (isset($_POST['save'])) { checkSession(); if (isset($_GET['xml'])) { $tokenValidation = validateToken('admin-core', 'post', false); if (empty($tokenValidation)) { return 'token_verify_fail'; } } else { validateToken('admin-core'); } $setting_changes = array('admin_features' => array()); // Cycle each feature and change things as required! foreach ($core_features as $id => $feature) { // Enabled? if (!empty($_POST['feature_' . $id])) { $setting_changes['admin_features'][] = $id; } // Setting values to change? if (isset($feature['settings'])) { foreach ($feature['settings'] as $key => $value) { if (empty($_POST['feature_' . $id]) || !empty($_POST['feature_' . $id]) && ($value < 2 || empty($modSettings[$key]))) { $setting_changes[$key] = !empty($_POST['feature_' . $id]) ? $value : !$value; } } } // Is there a call back for settings? if (isset($feature['setting_callback'])) { $returned_settings = $feature['setting_callback'](!empty($_POST['feature_' . $id])); if (!empty($returned_settings)) { $setting_changes = array_merge($setting_changes, $returned_settings); } } // Standard save callback? if (isset($feature['on_save'])) { $feature['on_save'](); } } // Make sure this one setting is a string! $setting_changes['admin_features'] = implode(',', $setting_changes['admin_features']); // Make any setting changes! updateSettings($setting_changes); // This is needed to let menus appear if cache > 2 if ($modSettings['cache_enable'] > 2) { clean_cache('data'); } // Any post save things? foreach ($core_features as $id => $feature) { // Standard save callback? if (isset($feature['save_callback'])) { $feature['save_callback'](!empty($_POST['feature_' . $id])); } } if (!isset($_REQUEST['xml'])) { redirectexit('action=admin;area=corefeatures;' . $context['session_var'] . '=' . $context['session_id']); } } // Put them in context. $context['features'] = array(); foreach ($core_features as $id => $feature) { $context['features'][$id] = array('title' => isset($feature['title']) ? $feature['title'] : $txt['core_settings_item_' . $id], 'desc' => isset($feature['desc']) ? $feature['desc'] : $txt['core_settings_item_' . $id . '_desc'], 'enabled' => in_array($id, $context['admin_features']), 'state' => in_array($id, $context['admin_features']) ? 'on' : 'off', 'url' => !empty($feature['url']) ? $scripturl . '?' . $feature['url'] . ';' . $context['session_var'] . '=' . $context['session_id'] : '', 'image' => (file_exists($settings['theme_dir'] . '/images/admin/feature_' . $id . '.png') ? $settings['images_url'] : $settings['default_images_url']) . '/admin/feature_' . $id . '.png'); } // Are they a new user? $context['is_new_install'] = !isset($modSettings['admin_features']); $context['force_disable_tabs'] = $context['is_new_install']; // Don't show them this twice! if ($context['is_new_install']) { updateSettings(array('admin_features' => '')); } // sub_template is already generic_xml and the token is created somewhere else if (isset($_REQUEST['xml'])) { return; } $context['sub_template'] = 'core_features'; $context['page_title'] = $txt['core_settings_title']; $context[$context['admin_menu_name']]['tab_data'] = array('title' => $txt['core_settings_title'], 'help' => '', 'description' => $txt['core_settings_desc']); // We love our tokens. createToken('admin-core'); }
function scheduled_daily_maintenance() { global $smcFunc, $modSettings, $sourcedir, $db_type; // First clean out the cache. clean_cache(); // If warning decrement is enabled and we have people who have not had a new warning in 24 hours, lower their warning level. list(, , $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']); if ($modSettings['warning_decrement']) { // Find every member who has a warning level... $request = $smcFunc['db_query']('', ' SELECT id_member, warning FROM {db_prefix}members WHERE warning > {int:no_warning}', array('no_warning' => 0)); $members = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { $members[$row['id_member']] = $row['warning']; } $smcFunc['db_free_result']($request); // Have some members to check? if (!empty($members)) { // Find out when they were last warned. $request = $smcFunc['db_query']('', ' SELECT id_recipient, MAX(log_time) AS last_warning FROM {db_prefix}log_comments WHERE id_recipient IN ({array_int:member_list}) AND comment_type = {string:warning} GROUP BY id_recipient', array('member_list' => array_keys($members), 'warning' => 'warning')); $member_changes = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { // More than 24 hours ago? if ($row['last_warning'] <= time() - 86400) { $member_changes[] = array('id' => $row['id_recipient'], 'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0); } } $smcFunc['db_free_result']($request); // Have some members to change? if (!empty($member_changes)) { foreach ($member_changes as $change) { $smcFunc['db_query']('', ' UPDATE {db_prefix}members SET warning = {int:warning} WHERE id_member = {int:id_member}', array('warning' => $change['warning'], 'id_member' => $change['id'])); } } } } // Do any spider stuff. if (!empty($modSettings['spider_mode']) && $modSettings['spider_mode'] > 1) { require_once $sourcedir . '/ManageSearchEngines.php'; consolidateSpiderStats(); } // Check the database version - for some buggy MySQL version. $server_version = $smcFunc['db_server_info'](); if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { updateSettings(array('db_mysql_group_by_fix' => '1')); } elseif (!empty($modSettings['db_mysql_group_by_fix'])) { $smcFunc['db_query']('', ' DELETE FROM {db_prefix}settings WHERE variable = {string:mysql_fix}', array('mysql_fix' => 'db_mysql_group_by_fix')); } // Regenerate the Diffie-Hellman keys if OpenID is enabled. if (!empty($modSettings['enableOpenID'])) { require_once $sourcedir . '/Subs-OpenID.php'; smf_openID_setup_DH(true); } elseif (!empty($modSettings['dh_keys'])) { $smcFunc['db_query']('', ' DELETE FROM {db_prefix}settings WHERE variable = {string:dh_keys}', array('dh_keys' => 'dh_keys')); } // Log we've done it... return true; }
<?php /** * @author OA Wu <*****@*****.**> * @copyright Copyright (c) 2015 OA Wu Design */ include_once 'base.php'; include_once 'functions/clean.php'; // file type name action // ======================================================================= // php clean cache [cell | file | model | [assets | static]] $file = array_shift($argv); $type = array_shift($argv); $name = array_shift($argv); switch (strtolower($type)) { case 'cache': $results = clean_cache($name); break; default: return console_error('指令錯誤!', '只接受 cache 指令。'); } $results = array_map(function ($result) { $count = 1; return color('Clean: ', 'g') . str_replace(FCPATH, '', $result, $count); }, $results); array_unshift($results, '清除成功!'); call_user_func_array('console_log', $results);
/** * Apply another type of (avatar, language, etc.) package. */ public function action_install2() { global $txt, $context, $boardurl, $scripturl, $modSettings; // Make sure we don't install this mod twice. checkSubmitOnce('check'); checkSession(); // If there's no file, what are we installing? if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') { redirectexit('action=admin;area=packages'); } $context['filename'] = $_REQUEST['package']; // If this is an uninstall, we'll have an id. $context['install_id'] = isset($_REQUEST['pid']) ? (int) $_REQUEST['pid'] : 0; require_once SUBSDIR . '/Package.subs.php'; require_once SUBSDIR . '/Themes.subs.php'; // @todo Perhaps do it in steps, if necessary? $context['uninstalling'] = $_REQUEST['sa'] == 'uninstall2'; // Set up the linktree for other. $context['linktree'][count($context['linktree']) - 1] = array('url' => $scripturl . '?action=admin;area=packages;sa=browse', 'name' => $context['uninstalling'] ? $txt['uninstall'] : $txt['extracting']); $context['page_title'] .= ' - ' . ($context['uninstalling'] ? $txt['uninstall'] : $txt['extracting']); $context['sub_template'] = 'extract_package'; if (!file_exists(BOARDDIR . '/packages/' . $context['filename'])) { fatal_lang_error('package_no_file', false); } // Load up the package FTP information? create_chmod_control(array(), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=' . $_REQUEST['sa'] . ';package=' . $_REQUEST['package'])); // Make sure temp directory exists and is empty! if (file_exists(BOARDDIR . '/packages/temp')) { deltree(BOARDDIR . '/packages/temp', false); } else { mktree(BOARDDIR . '/packages/temp', 0777); } // Let the unpacker do the work. if (is_file(BOARDDIR . '/packages/' . $context['filename'])) { $context['extracted_files'] = read_tgz_file(BOARDDIR . '/packages/' . $context['filename'], BOARDDIR . '/packages/temp'); if (!file_exists(BOARDDIR . '/packages/temp/package-info.xml')) { foreach ($context['extracted_files'] as $file) { if (basename($file['filename']) == 'package-info.xml') { $context['base_path'] = dirname($file['filename']) . '/'; break; } } } if (!isset($context['base_path'])) { $context['base_path'] = ''; } } elseif (is_dir(BOARDDIR . '/packages/' . $context['filename'])) { copytree(BOARDDIR . '/packages/' . $context['filename'], BOARDDIR . '/packages/temp'); $context['extracted_files'] = listtree(BOARDDIR . '/packages/temp'); $context['base_path'] = ''; } else { fatal_lang_error('no_access', false); } // Are we installing this into any custom themes? $custom_themes = array(1); $known_themes = explode(',', $modSettings['knownThemes']); if (!empty($_POST['custom_theme'])) { foreach ($_POST['custom_theme'] as $tid) { if (in_array($tid, $known_themes)) { $custom_themes[] = (int) $tid; } } } // Now load up the paths of the themes that we need to know about. $theme_paths = getThemesPathbyID($custom_themes); $themes_installed = array(1); // Are there any theme copying that we want to take place? $context['theme_copies'] = array('require-file' => array(), 'require-dir' => array()); if (!empty($_POST['theme_changes'])) { foreach ($_POST['theme_changes'] as $change) { if (empty($change)) { continue; } $theme_data = unserialize(base64_decode($change)); if (empty($theme_data['type'])) { continue; } $themes_installed[] = $theme_data['id']; $context['theme_copies'][$theme_data['type']][$theme_data['orig']][] = $theme_data['future']; } } // Get the package info... $packageInfo = getPackageInfo($context['filename']); if (!is_array($packageInfo)) { fatal_lang_error($packageInfo); } $packageInfo['filename'] = $context['filename']; // Set the type of extraction... $context['extract_type'] = isset($packageInfo['type']) ? $packageInfo['type'] : 'modification'; // Create a backup file to roll back to! (but if they do this more than once, don't run it a zillion times.) if (!empty($modSettings['package_make_full_backups']) && (!isset($_SESSION['last_backup_for']) || $_SESSION['last_backup_for'] != $context['filename'] . ($context['uninstalling'] ? '$$' : '$'))) { $_SESSION['last_backup_for'] = $context['filename'] . ($context['uninstalling'] ? '$$' : '$'); // @todo Internationalize this? package_create_backup(($context['uninstalling'] ? 'backup_' : 'before_') . strtok($context['filename'], '.')); } // The mod isn't installed.... unless proven otherwise. $context['is_installed'] = false; // Is it actually installed? $package_installed = isPackageInstalled($packageInfo['id']); // Wait, it's not installed yet! // @todo Replace with a better error message! if (!isset($package_installed['old_version']) && $context['uninstalling']) { deltree(BOARDDIR . '/packages/temp'); fatal_error('Hacker?', false); } elseif ($context['uninstalling']) { $install_log = parsePackageInfo($packageInfo['xml'], false, 'uninstall'); // Gadzooks! There's no uninstaller at all!? if (empty($install_log)) { fatal_lang_error('package_uninstall_cannot', false); } // They can only uninstall from what it was originally installed into. foreach ($theme_paths as $id => $data) { if ($id != 1 && !in_array($id, $package_installed['old_themes'])) { unset($theme_paths[$id]); } } } elseif (isset($package_installed['old_version']) && $package_installed['old_version'] != $packageInfo['version']) { // Look for an upgrade... $install_log = parsePackageInfo($packageInfo['xml'], false, 'upgrade', $package_installed['old_version']); // There was no upgrade.... if (empty($install_log)) { $context['is_installed'] = true; } else { // Upgrade previous themes only! foreach ($theme_paths as $id => $data) { if ($id != 1 && !in_array($id, $package_installed['old_themes'])) { unset($theme_paths[$id]); } } } } elseif (isset($package_installed['old_version']) && $package_installed['old_version'] == $packageInfo['version']) { $context['is_installed'] = true; } if (!isset($package_installed['old_version']) || $context['is_installed']) { $install_log = parsePackageInfo($packageInfo['xml'], false, 'install'); } $context['install_finished'] = false; // We're gonna be needing the table db functions! ...Sometimes. $table_installer = db_table(); // @todo Make a log of any errors that occurred and output them? if (!empty($install_log)) { $failed_steps = array(); $failed_count = 0; foreach ($install_log as $action) { $failed_count++; if ($action['type'] == 'modification' && !empty($action['filename'])) { if ($action['boardmod']) { $mod_actions = parseBoardMod(file_get_contents(BOARDDIR . '/packages/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths); } else { $mod_actions = parseModification(file_get_contents(BOARDDIR . '/packages/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths); } // Any errors worth noting? foreach ($mod_actions as $key => $action) { if ($action['type'] == 'failure') { $failed_steps[] = array('file' => $action['filename'], 'large_step' => $failed_count, 'sub_step' => $key, 'theme' => 1); } // Gather the themes we installed into. if (!empty($action['is_custom'])) { $themes_installed[] = $action['is_custom']; } } } elseif ($action['type'] == 'code' && !empty($action['filename'])) { // This is just here as reference for what is available. global $txt, $modSettings, $context; // Now include the file and be done with it ;). if (file_exists(BOARDDIR . '/packages/temp/' . $context['base_path'] . $action['filename'])) { require BOARDDIR . '/packages/temp/' . $context['base_path'] . $action['filename']; } } elseif ($action['type'] == 'credits') { // Time to build the billboard $credits_tag = array('url' => $action['url'], 'license' => $action['license'], 'copyright' => $action['copyright'], 'title' => $action['title']); } elseif ($action['type'] == 'hook' && isset($action['hook'], $action['function'])) { if ($action['reverse']) { remove_integration_function($action['hook'], $action['function'], $action['include_file']); } else { add_integration_function($action['hook'], $action['function'], $action['include_file']); } } elseif ($action['type'] == 'database' && !empty($action['filename']) && (!$context['uninstalling'] || !empty($_POST['do_db_changes']))) { // These can also be there for database changes. global $txt, $modSettings, $context; // Let the file work its magic ;) if (file_exists(BOARDDIR . '/packages/temp/' . $context['base_path'] . $action['filename'])) { require BOARDDIR . '/packages/temp/' . $context['base_path'] . $action['filename']; } } elseif ($action['type'] == 'redirect' && !empty($action['redirect_url'])) { $context['redirect_url'] = $action['redirect_url']; $context['redirect_text'] = !empty($action['filename']) && file_exists(BOARDDIR . '/packages/temp/' . $context['base_path'] . $action['filename']) ? file_get_contents(BOARDDIR . '/packages/temp/' . $context['base_path'] . $action['filename']) : ($context['uninstalling'] ? $txt['package_uninstall_done'] : $txt['package_installed_done']); $context['redirect_timeout'] = $action['redirect_timeout']; // Parse out a couple of common urls. $urls = array('$boardurl' => $boardurl, '$scripturl' => $scripturl, '$session_var' => $context['session_var'], '$session_id' => $context['session_id']); $context['redirect_url'] = strtr($context['redirect_url'], $urls); } } package_flush_cache(); // First, ensure this change doesn't get removed by putting a stake in the ground (So to speak). package_put_contents(BOARDDIR . '/packages/installed.list', time()); // See if this is already installed $is_upgrade = false; $old_db_changes = array(); $package_check = isPackageInstalled($packageInfo['id']); // Change the installed state as required. if (!empty($package_check['install_state'])) { if ($context['uninstalling']) { setPackageState($package_check['package_id']); } else { // not uninstalling so must be an upgrade $is_upgrade = true; $old_db_changes = empty($package_check['db_changes']) ? array() : $package_check['db_changes']; } } // Assuming we're not uninstalling, add the entry. if (!$context['uninstalling']) { // Any db changes from older version? $table_log = $table_installer->package_log(); if (!empty($old_db_changes)) { $db_package_log = empty($table_log) ? $old_db_changes : array_merge($old_db_changes, $table_log); } else { $db_package_log = $table_log; } // If there are some database changes we might want to remove then filter them out. if (!empty($db_package_log)) { // We're really just checking for entries which are create table AND add columns (etc). $tables = array(); usort($db_package_log, array($this, '_sort_table_first')); foreach ($db_package_log as $k => $log) { if ($log[0] == 'remove_table') { $tables[] = $log[1]; } elseif (in_array($log[1], $tables)) { unset($db_package_log[$k]); } } $package_installed['db_changes'] = serialize($db_package_log); } else { $package_installed['db_changes'] = ''; } // What themes did we actually install? $themes_installed = array_unique($themes_installed); $themes_installed = implode(',', $themes_installed); // What failed steps? $failed_step_insert = serialize($failed_steps); // Credits tag? $credits_tag = empty($credits_tag) ? '' : serialize($credits_tag); // Add to the log packages addPackageLog($packageInfo, $failed_step_insert, $themes_installed, $package_installed['db_changes'], $is_upgrade, $credits_tag); } $context['install_finished'] = true; } // If there's database changes - and they want them removed - let's do it last! if (!empty($package_installed['db_changes']) && !empty($_POST['do_db_changes'])) { foreach ($package_installed['db_changes'] as $change) { if ($change[0] == 'remove_table' && isset($change[1])) { $table_installer->db_drop_table($change[1]); } elseif ($change[0] == 'remove_column' && isset($change[2])) { $table_installer->db_remove_column($change[1], $change[2]); } elseif ($change[0] == 'remove_index' && isset($change[2])) { $table_installer->db_remove_index($change[1], $change[2]); } } } // Clean house... get rid of the evidence ;). if (file_exists(BOARDDIR . '/packages/temp')) { deltree(BOARDDIR . '/packages/temp'); } // Log what we just did. logAction($context['uninstalling'] ? 'uninstall_package' : (!empty($is_upgrade) ? 'upgrade_package' : 'install_package'), array('package' => Util::htmlspecialchars($packageInfo['name']), 'version' => Util::htmlspecialchars($packageInfo['version'])), 'admin'); // Just in case, let's clear the whole cache to avoid anything going up the swanny. clean_cache(); // Restore file permissions? create_chmod_control(array(), array(), true); }
/** * * @global <type> $quality * @param <type> $mime_type * @param <type> $image_resized */ function show_image($mime_type, $canvas) { global $quality; $cache_file = get_cache_file(); switch ($mime_type) { case 'jpg': imagejpeg($canvas, $cache_file, $quality); break; default: case 'png': imagepng($canvas, $cache_file, floor($quality * 0.09)); break; } // remove image from memory imagedestroy($canvas); // if not in cache then clear some space and generate a new file clean_cache(); show_cache_file($mime_type); }
exit("Cannot write zipfile {$F}\n"); } $N->addEmptyDir(GNAME); foreach (get_images_list() as $C) { $N->addFile(IDIR . $C, GNAME . '/' . $C); } $N->close(); } function set_download_headers($O) { header("Content-Disposition: attachment; filename=\"" . $O . "\""); header("Content-Description: File Transfer"); header("Content-Transfer-Encoding: binary"); } if (isset($_GET['cleancache'])) { clean_cache(); echo "Done"; exit; } if (isset($_POST['createzip'])) { $F = zip_path(); if (!file_exists($F) || !_CACHE) { create_zip($F); if (!_CACHE) { header('Content-Type: application/json'); echo json_encode(array('zip' => basename($F))); } } exit; } if (isset($_GET['zip'])) {
function deleteBoards($boards_to_remove, $moveChildrenTo = null) { global $sourcedir, $boards, $smcFunc; // No boards to delete? Return! if (empty($boards_to_remove)) { return; } getBoardTree(); // If $moveChildrenTo is set to null, include the children in the removal. if ($moveChildrenTo === null) { // Get a list of the child boards that will also be removed. $child_boards_to_remove = array(); foreach ($boards_to_remove as $board_to_remove) { recursiveBoards($child_boards_to_remove, $boards[$board_to_remove]['tree']); } // Merge the children with their parents. if (!empty($child_boards_to_remove)) { $boards_to_remove = array_unique(array_merge($boards_to_remove, $child_boards_to_remove)); } } else { foreach ($boards_to_remove as $id_board) { // !!! Separate category? if ($moveChildrenTo === 0) { fixChildren($id_board, 0, 0); } else { fixChildren($id_board, $boards[$moveChildrenTo]['level'] + 1, $moveChildrenTo); } } } // Delete ALL topics in the selected boards (done first so topics can't be marooned.) $request = $smcFunc['db_query']('', ' SELECT id_topic FROM {db_prefix}topics WHERE id_board IN ({array_int:boards_to_remove})', array('boards_to_remove' => $boards_to_remove)); $topics = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { $topics[] = $row['id_topic']; } $smcFunc['db_free_result']($request); require_once $sourcedir . '/RemoveTopic.php'; removeTopics($topics, false); // Delete the board's logs. $smcFunc['db_query']('', ' DELETE FROM {db_prefix}log_mark_read WHERE id_board IN ({array_int:boards_to_remove})', array('boards_to_remove' => $boards_to_remove)); $smcFunc['db_query']('', ' DELETE FROM {db_prefix}log_boards WHERE id_board IN ({array_int:boards_to_remove})', array('boards_to_remove' => $boards_to_remove)); $smcFunc['db_query']('', ' DELETE FROM {db_prefix}log_notify WHERE id_board IN ({array_int:boards_to_remove})', array('boards_to_remove' => $boards_to_remove)); // Delete this board's moderators. $smcFunc['db_query']('', ' DELETE FROM {db_prefix}moderators WHERE id_board IN ({array_int:boards_to_remove})', array('boards_to_remove' => $boards_to_remove)); // Delete any extra events in the calendar. $smcFunc['db_query']('', ' DELETE FROM {db_prefix}calendar WHERE id_board IN ({array_int:boards_to_remove})', array('boards_to_remove' => $boards_to_remove)); // Delete any message icons that only appear on these boards. $smcFunc['db_query']('', ' DELETE FROM {db_prefix}message_icons WHERE id_board IN ({array_int:boards_to_remove})', array('boards_to_remove' => $boards_to_remove)); // Delete the boards. $smcFunc['db_query']('', ' DELETE FROM {db_prefix}boards WHERE id_board IN ({array_int:boards_to_remove})', array('boards_to_remove' => $boards_to_remove)); // Latest message/topic might not be there anymore. updateStats('message'); updateStats('topic'); updateSettings(array('calendar_updated' => time())); // Plus reset the cache to stop people getting odd results. updateSettings(array('settings_updated' => time())); // Clean the cache as well. clean_cache('data'); // Let's do some serious logging. foreach ($boards_to_remove as $id_board) { logAction('delete_board', array('boardname' => $boards[$id_board]['name']), 'admin'); } reorderBoards(); }
function MaintainCleanCache() { global $context, $txt; // Just wipe the whole cache directory! clean_cache(); $context['maintenance_finished'] = $txt['maintain_cache']; }
/** * 临时查看主题(管理员预览用) * @author 郑钟良<*****@*****.**> */ public function lookTheme() { $aTheme = I('theme', '', 'text'); cookie('TO_LOOK_THEME', $aTheme, array('prefix' => 'OSV2', 'expire' => 180)); //重设cookie S('conf_THEME_NOW_THEME', $aTheme, 180); //重设modC的session clean_cache('./Runtime/Cache/'); //清除模板缓存 redirect(U('Home/Index/index')); }
<?php require_once "basic/basic.php"; $host_name = htmlspecialchars($_GET["whoami"]); $cache_path = htmlspecialchars($_GET["cache_path"]); function clean_cache($path) { unlink($path); $dir_name = dirname($path); for ($i = 1; $i <= 3; $i++) { rmdir($dir_name); $dir_name = dirname($dir_name); } } $host_validate = validateHostByHostname($host_name); if ($host_validate == "host_valid") { clean_cache(WORK_DIR . $cache_path); }
/** * Wipes the whole cache directory. * This only applies to SMF's own cache directory, though. */ function MaintainCleanCache() { global $context, $txt; checkSession(); validateToken('admin-maint'); // Just wipe the whole cache directory! clean_cache(); $context['maintenance_finished'] = $txt['maintain_cache']; }