$vbcollapse = array(); if (!empty($vbulletin->GPC['vbulletin_collapse'])) { $val = preg_split('#\\n#', $vbulletin->GPC['vbulletin_collapse'], -1, PREG_SPLIT_NO_EMPTY); foreach ($val as $key) { $vbcollapse["collapseobj_{$key}"] = 'display:none;'; $vbcollapse["collapseimg_{$key}"] = '_collapsed'; $vbcollapse["collapsecel_{$key}"] = '_collapsed'; } unset($val); } // ############################################################################# // start server too busy $servertoobusy = false; if (PHP_OS == 'Linux' and $vbulletin->options['loadlimit'] > 0) { if (!is_array($vbulletin->loadcache) or $vbulletin->loadcache['lastcheck'] < TIMENOW - 300) { update_loadavg(); } if ($vbulletin->loadcache['loadavg'] > $vbulletin->options['loadlimit']) { $servertoobusy = true; } } // ############################################################################# // do headers exec_headers(); // ############################################################################# // set the referrer cookie if URI contains a referrerid if ($vbulletin->GPC['referrerid'] and !$vbulletin->GPC[COOKIE_PREFIX . 'referrerid'] and !$vbulletin->userinfo['userid'] and $vbulletin->options['usereferrer']) { if ($referrerid = verify_id('user', $vbulletin->GPC['referrerid'], 0)) { vbsetcookie('referrerid', $referrerid); } }
/** * Determines if the server is over the defined load limits * * @return bool */ protected function server_overloaded() { global $vbulletin; if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN' and $vbulletin->options['loadlimit'] > 0) { if (!is_array($vbulletin->loadcache) or $vbulletin->loadcache['lastcheck'] < TIMENOW - $vbulletin->options['recheckfrequency']) { update_loadavg(); } if ($vbulletin->loadcache['loadavg'] > $vbulletin->options['loadlimit']) { return true; } } return false; }
/** * Updates the setting table based on data passed in then rebuilds the datastore. * Only entries in the array are updated (allows partial updates). * * @param array Array of settings. Format: [setting_name] = new_value */ function save_settings($settings) { global $vbulletin, $vbphrase, $stylevar; $varnames = array(); foreach (array_keys($settings) as $varname) { $varnames[] = $vbulletin->db->escape_string($varname); } $oldsettings = $vbulletin->db->query_read("\n\t\tSELECT value, varname, datatype, optioncode\n\t\tFROM " . TABLE_PREFIX . "setting\n\t\tWHERE varname IN ('" . implode("', '", $varnames) . "')\n\t\tORDER BY varname\n\t"); while ($oldsetting = $vbulletin->db->fetch_array($oldsettings)) { switch ($oldsetting['varname']) { // ************************************************** case 'bbcode_html_colors': $settings['bbcode_html_colors'] = serialize($settings['bbcode_html_colors']); break; // ************************************************** // ************************************************** case 'styleid': $vbulletin->db->query_write("\n\t\t\t\t\tUPDATE " . TABLE_PREFIX . "style\n\t\t\t\t\tSET userselect = 1\n\t\t\t\t\tWHERE styleid = " . $settings['styleid'] . "\n\t\t\t\t"); break; // ************************************************** // ************************************************** case 'banemail': build_datastore('banemail', $settings['banemail']); $settings['banemail'] = ''; break; // ************************************************** // ************************************************** case 'editormodes': $vbulletin->input->clean_array_gpc('p', array('fe' => TYPE_UINT, 'qr' => TYPE_UINT, 'qe' => TYPE_UINT)); $settings['editormodes'] = serialize(array('fe' => $vbulletin->GPC['fe'], 'qr' => $vbulletin->GPC['qr'], 'qe' => $vbulletin->GPC['qe'])); break; // ************************************************** // ************************************************** case 'cookiepath': case 'cookiedomain': if ($settings[$oldsetting['varname'] . '_other'] and $settings[$oldsetting['varname'] . '_value']) { $settings[$oldsetting['varname']] = $settings[$oldsetting['varname'] . '_value']; } break; // ************************************************** // ************************************************** default: ($hook = vBulletinHook::fetch_hook('admin_options_processing')) ? eval($hook) : false; if ($oldsetting['optioncode'] == 'multiinput') { $store = array(); foreach ($settings["{$oldsetting['varname']}"] as $value) { if ($value != '') { $store[] = $value; } } $settings["{$oldsetting['varname']}"] = serialize($store); } else { if (preg_match('#^usergroup:[0-9]+$#', $oldsetting['optioncode'])) { // serialize the array of usergroup inputs if (!is_array($settings["{$oldsetting['varname']}"])) { $settings["{$oldsetting['varname']}"] = array(); } $settings["{$oldsetting['varname']}"] = array_map('intval', $settings["{$oldsetting['varname']}"]); $settings["{$oldsetting['varname']}"] = serialize($settings["{$oldsetting['varname']}"]); } } } $newvalue = validate_setting_value($settings["{$oldsetting['varname']}"], $oldsetting['datatype']); // this is a strict type check because we want '' to be different from 0 // some special cases below only use != checks to see if the logical value has changed if (strval($oldsetting['value']) !== strval($newvalue)) { switch ($oldsetting['varname']) { case 'activememberdays': case 'activememberoptions': if ($oldsetting['value'] != $newvalue) { $vbulletin->options["{$oldsetting['varname']}"] = $newvalue; require_once DIR . '/includes/functions_databuild.php'; build_birthdays(); } break; case 'showevents': case 'showholidays': if ($oldsetting['value'] != $newvalue) { $vbulletin->options["{$oldsetting['varname']}"] = $newvalue; require_once DIR . '/includes/functions_calendar.php'; build_events(); } break; case 'languageid': if ($oldsetting['value'] != $newvalue) { $vbulletin->options['languageid'] = $newvalue; require_once DIR . '/includes/adminfunctions_language.php'; build_language($vbulletin->options['languageid']); } break; case 'cpstylefolder': $admindm =& datamanager_init('Admin', $vbulletin, ERRTYPE_CP); $admindm->set_existing($vbulletin->userinfo); $admindm->set('cssprefs', $newvalue); $admindm->save(); unset($admindm); break; case 'storecssasfile': if (!is_demo_mode() and $oldsetting['value'] != $newvalue) { $vbulletin->options['storecssasfile'] = $newvalue; require_once DIR . '/includes/adminfunctions_template.php'; print_rebuild_style(-1, '', 1, 0, 0, 0); } break; case 'loadlimit': update_loadavg(); break; case 'view_tagcloud_as_usergroup': build_datastore('tagcloud', serialize(''), 1); break; case 'censorwords': case 'codemaxlines': if ($oldsetting['value'] != $newvalue) { $vbulletin->db->query_write("TRUNCATE TABLE " . TABLE_PREFIX . "postparsed"); if ($vbulletin->options['templateversion'] >= '3.6') { $vbulletin->db->query_write("TRUNCATE TABLE " . TABLE_PREFIX . "sigparsed"); } } ($hook = vBulletinHook::fetch_hook('admin_options_processing_censorcode')) ? eval($hook) : false; break; default: ($hook = vBulletinHook::fetch_hook('admin_options_processing_build')) ? eval($hook) : false; } if (is_demo_mode() and in_array($oldsetting['varname'], array('storecssasfile', 'attachfile', 'usefileavatar', 'errorlogdatabase', 'errorlogsecurity', 'safeupload', 'tmppath'))) { continue; } $vbulletin->db->query_write("\n\t\t\t\tUPDATE " . TABLE_PREFIX . "setting\n\t\t\t\tSET value = '" . $vbulletin->db->escape_string($newvalue) . "'\n\t\t\t\tWHERE varname = '" . $vbulletin->db->escape_string($oldsetting['varname']) . "'\n\t\t\t"); } } build_options(); }
/** * Updates the setting table based on data passed in then rebuilds the datastore. * Only entries in the array are updated (allows partial updates). * * @param array Array of settings. Format: [setting_name] = new_value * */ function save_settings($settings) { global $vbulletin, $vbphrase; //a few variables to track changes for processing after all variables are updated. $rebuildstyle = false; $templatecachepathchanged = false; $oldtemplatepath = null; $newtemplatepath = null; $userContext = vB::getUserContext(); $cleaner = vB::getCleaner(); $canAdminAll = $userContext->hasAdminPermission('canadminsettingsall'); $oldsettings = vB::getDbAssertor()->assertQuery('vBAdmincp:getCurrentSettings', array('varname' => array_keys($settings))); foreach ($oldsettings as $oldsetting) { //check the setting and group permissions if (!empty($oldsetting['adminperm']) and !$userContext->hasAdminPermission($oldsetting['adminperm']) or !empty($oldsetting['groupperm']) and !$userContext->hasAdminPermission($oldsetting['groupperm'])) { throw new vB_Exception_Api('no_permission'); } switch ($oldsetting['varname']) { // ************************************************** case 'bbcode_html_colors': $settings['bbcode_html_colors'] = serialize($settings['bbcode_html_colors']); break; // ************************************************** // ************************************************** case 'styleid': vB::getDbAssertor()->assertQuery('vBForum:style', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, 'userselect' => 1, vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'styleid', 'value' => $settings['styleid'], 'operator' => vB_dB_Query::OPERATOR_EQ)))); break; // ************************************************** // ************************************************** case 'banemail': vB::getDatastore()->build('banemail', $settings['banemail']); $settings['banemail'] = ''; break; // ************************************************** // ************************************************** case 'editormodes': $vbulletin->input->clean_array_gpc('p', array('fe' => vB_Cleaner::TYPE_UINT, 'qr' => vB_Cleaner::TYPE_UINT, 'qe' => vB_Cleaner::TYPE_UINT)); $settings['editormodes'] = serialize(array('fe' => $vbulletin->GPC['fe'], 'qr' => $vbulletin->GPC['qr'], 'qe' => $vbulletin->GPC['qe'])); break; // ************************************************** // ************************************************** case 'attachresizes': $vbulletin->input->clean_array_gpc('p', array('attachresizes' => vB_Cleaner::TYPE_ARRAY_UINT)); $value = @unserialize($oldsetting['value']); $invalidate = array(); if ($value[vB_Api_Filedata::SIZE_ICON] != $vbulletin->GPC['attachresizes'][vB_Api_Filedata::SIZE_ICON]) { $invalidate[] = vB_Api_Filedata::SIZE_ICON; } if ($value[vB_Api_Filedata::SIZE_THUMB] != $vbulletin->GPC['attachresizes'][vB_Api_Filedata::SIZE_THUMB]) { $invalidate[] = vB_Api_Filedata::SIZE_THUMB; } if ($value[vB_Api_Filedata::SIZE_SMALL] != $vbulletin->GPC['attachresizes'][vB_Api_Filedata::SIZE_SMALL]) { $invalidate[] = vB_Api_Filedata::SIZE_SMALL; } if ($value[vB_Api_Filedata::SIZE_MEDIUM] != $vbulletin->GPC['attachresizes'][vB_Api_Filedata::SIZE_MEDIUM]) { $invalidate[] = vB_Api_Filedata::SIZE_MEDIUM; } if ($value[vB_Api_Filedata::SIZE_LARGE] != $vbulletin->GPC['attachresizes'][vB_Api_Filedata::SIZE_LARGE]) { $invalidate[] = vB_Api_Filedata::SIZE_LARGE; } if (!empty($invalidate)) { vB::getDbAssertor()->update('vBForum:filedataresize', array('reload' => 1), array('resize_type' => $invalidate)); } $settings['attachresizes'] = serialize(array(vB_Api_Filedata::SIZE_ICON => $vbulletin->GPC['attachresizes'][vB_Api_Filedata::SIZE_ICON], vB_Api_Filedata::SIZE_THUMB => $vbulletin->GPC['attachresizes'][vB_Api_Filedata::SIZE_THUMB], vB_Api_Filedata::SIZE_SMALL => $vbulletin->GPC['attachresizes'][vB_Api_Filedata::SIZE_SMALL], vB_Api_Filedata::SIZE_MEDIUM => $vbulletin->GPC['attachresizes'][vB_Api_Filedata::SIZE_MEDIUM], vB_Api_Filedata::SIZE_LARGE => $vbulletin->GPC['attachresizes'][vB_Api_Filedata::SIZE_LARGE])); break; case 'thumbquality': if ($oldsetting['value'] != $settings['thumbquality']) { vB::getDbAssertor()->update('vBForum:filedataresize', array('reload' => 1), vB_dB_Query::CONDITION_ALL); } break; // ************************************************** // ************************************************** case 'cookiepath': case 'cookiedomain': if ($settings[$oldsetting['varname'] . '_other'] and $settings[$oldsetting['varname'] . '_value']) { $settings[$oldsetting['varname']] = $settings[$oldsetting['varname'] . '_value']; } break; // ************************************************** // ************************************************** default: // Legacy Hook 'admin_options_processing' Removed // if ($oldsetting['optioncode'] == 'multiinput') { $store = array(); foreach ($settings["{$oldsetting['varname']}"] as $value) { if ($value != '') { $store[] = $value; } } $settings["{$oldsetting['varname']}"] = serialize($store); } else { if (preg_match('#^(usergroup|forum)s?:([0-9]+|all|none)$#', $oldsetting['optioncode'])) { // serialize the array of usergroup inputs if (!is_array($settings["{$oldsetting['varname']}"])) { $settings["{$oldsetting['varname']}"] = array(); } $settings["{$oldsetting['varname']}"] = array_map('intval', $settings["{$oldsetting['varname']}"]); $settings["{$oldsetting['varname']}"] = serialize($settings["{$oldsetting['varname']}"]); } } } $newvalue = validate_setting_value($settings["{$oldsetting['varname']}"], $oldsetting['datatype']); if ($canAdminAll and isset($_POST['adminperm_' . $oldsetting[varname]])) { $newAdminPerm = substr($cleaner->clean($_POST['adminperm_' . $oldsetting[varname]], vB_Cleaner::TYPE_STR), 0, 32); } else { $newAdminPerm = $oldsetting['adminperm']; } // this is a strict type check because we want '' to be different from 0 // some special cases below only use != checks to see if the logical value has changed if ($oldsetting['value'] === NULL or strval($oldsetting['value']) !== strval($newvalue) or strval($oldsetting['adminperm']) !== strval($newAdminPerm)) { switch ($oldsetting['varname']) { case 'cache_templates_as_files': if (!is_demo_mode()) { $templatecachepathchanged = true; } break; case 'template_cache_path': if (!is_demo_mode()) { $oldtemplatepath = strval($oldsetting['value']); $newtemplatepath = $newvalue; } break; case 'languageid': if ($oldsetting['value'] != $newvalue) { vB::getDatastore()->setOption('languageid', $newvalue, false); require_once DIR . '/includes/adminfunctions_language.php'; build_language($newvalue); } break; case 'cpstylefolder': $admindm =& datamanager_init('Admin', $vbulletin, vB_DataManager_Constants::ERRTYPE_CP); $admindm->set_existing(vB::getCurrentSession()->fetch_userinfo()); $admindm->set('cssprefs', $newvalue); $admindm->save(); unset($admindm); break; case 'attachthumbssize': if ($oldsetting['value'] != $newvalue) { $rebuildstyle = true; } case 'storecssasfile': if (!is_demo_mode() and $oldsetting['value'] != $newvalue) { vB::getDatastore()->setOption('storecssasfile', $newvalue, false); $rebuildstyle = true; } break; case 'loadlimit': update_loadavg(); break; case 'tagcloud_usergroup': build_datastore('tagcloud', serialize(''), 1); break; case 'censorwords': case 'codemaxlines': case 'url_nofollow': case 'url_nofollow_whitelist': if ($oldsetting['value'] != $newvalue) { if (vB::getDatastore()->getOption('templateversion') >= '3.6') { vB::getDbAssertor()->assertQuery('truncateTable', array('table' => 'sigparsed')); } } // Legacy Hook 'admin_options_processing_censorcode' Removed // break; case 'album_recentalbumdays': if ($oldsetting['value'] > $newvalue) { require_once DIR . '/includes/functions_album.php'; exec_rebuild_album_updates(); } default: // Legacy Hook 'admin_options_processing_build' Removed // } if (is_demo_mode() and in_array($oldsetting['varname'], array('cache_templates_as_files', 'template_cache_path', 'storecssasfile', 'attachfile', 'usefileavatar', 'errorlogdatabase', 'errorlogsecurity', 'safeupload', 'tmppath'))) { continue; } $updateSetting = vB::getDbAssertor()->assertQuery('setting', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, 'value' => $newvalue, 'adminperm' => $newAdminPerm, vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'varname', 'value' => $oldsetting['varname'], 'operator' => vB_dB_Query::OPERATOR_EQ)))); } } if (!isset($oldsetting)) { return false; } vB::getDatastore()->build_options(); if (defined('DEV_AUTOEXPORT') and DEV_AUTOEXPORT) { require_once DIR . '/includes/functions_filesystemxml.php'; $xml = get_settings_export_xml('vbulletin'); autoexport_write_file_with_backup(DIR . '/install/vbulletin-settings.xml', $xml); } //handle changes for cache_templates_as_files and template_cache_path //we do it here because there are interactions between them and we don't //want to redo the chache changes twice if both are changed. $api = vB_Api::instanceInternal('template'); if ($templatecachepathchanged or !is_null($oldtemplatepath) and !is_null($newtemplatepath)) { if (vB::getDatastore()->getOption('cache_templates_as_files')) { if (!is_null($oldtemplatepath)) { //temporarily set the datastore path to the old value to clear it. vB::getDatastore()->setOption('template_cache_path', $oldtemplatepath, false); $api->deleteAllTemplateFiles(); vB::getDatastore()->setOption('template_cache_path', $newtemplatepath, false); } $api->saveAllTemplatesToFile(); } else { //we we changed directories and the cache is off, delete from the old directory if (!is_null($oldtemplatepath)) { vB::getDatastore()->setOption('template_cache_path', $oldtemplatepath, false); $api->deleteAllTemplateFiles(); vB::getDatastore()->setOption('template_cache_path', $newtemplatepath, false); } else { $api->deleteAllTemplateFiles(); } } } if ($rebuildstyle) { require_once DIR . '/includes/adminfunctions_template.php'; print_rebuild_style(-1, '', 1, 0, 0, 0); } return true; }