public function testElggSaveConfigForCurrentSiteConfig() { global $CONFIG; $name = 'foo' . rand(0, 1000); $value = 'test'; $this->assertTrue(elgg_save_config($name, $value)); $this->assertIdentical($value, elgg_get_config($name)); $this->assertIdentical($value, $CONFIG->{$name}); $this->assertTrue(elgg_remove_config($name)); }
<?php /** * Elgg 3.0.0 upgrade 2016101400 * security-defaults * * Add the default settings */ elgg_save_config('security_protect_upgrade', true); elgg_save_config('security_notify_admins', true); elgg_save_config('security_notify_user_password', true); elgg_save_config('security_email_require_password', true);
/** * Returns minimum and maximum lengths of words for MySQL search * This function looks for stored config values, and, if none set, * queries the DB and saves them * @return stdClass An object with min and max properties */ function search_get_ft_min_max() { $min = (int) elgg_get_config('search_ft_min_word_len'); $max = (int) elgg_get_config('search_ft_max_word_len'); if (!$min || !$max) { // defaults from MySQL on Ubuntu Linux $min = 4; $max = 90; try { $result = get_data_row('SELECT @@ft_min_word_len as min, @@ft_max_word_len as max'); $min = $result->min; $max = $result->max; } catch (DatabaseException $e) { // some servers don't have these values set which leads to exception // we ignore the exception } elgg_save_config('search_ft_min_word_len', $min); elgg_save_config('search_ft_max_word_len', $max); } $ft = new stdClass(); $ft->min = $min; $ft->max = $max; return $ft; }
<?php /** * Edit a custom profile field */ $id = get_input('id'); $label = get_input('label'); if (!elgg_get_config("admin_defined_profile_{$id}")) { register_error(elgg_echo('profile:editdefault:fail')); forward(REFERER); } if (elgg_save_config("admin_defined_profile_{$id}", $label)) { system_message(elgg_echo('profile:editdefault:success')); } else { register_error(elgg_echo('profile:editdefault:fail')); } forward(REFERER);
/** * Elgg profile plugin edit default profile action * */ $label = get_input('label'); $type = get_input('type'); $fieldlist = elgg_get_config('profile_custom_fields'); if (!$fieldlist && $fieldlist !== '0') { $fieldlist = ''; $id = 0; } else { $fieldlistarray = explode(',', $fieldlist); foreach ($fieldlistarray as $key => $value) { $fieldlistarray[$key] = (int) $value; } $id = max($fieldlistarray) + 1; } if ($label && $type) { if ($fieldlist !== '') { $fieldlist .= ','; } $fieldlist .= "{$id}"; if (elgg_save_config("admin_defined_profile_{$id}", $label) && elgg_save_config("admin_defined_profile_type_{$id}", $type) && elgg_save_config('profile_custom_fields', $fieldlist)) { system_message(elgg_echo('profile:editdefault:success')); } else { register_error(elgg_echo('profile:editdefault:fail')); } } else { register_error(elgg_echo('profile:editdefault:fail')); } forward(REFERER);
* Elgg 3.0.0 upgrade 2016110600 * datalist_into_config * * Merges datalists table data into config */ $dbprefix = elgg_get_config('dbprefix'); $exists = get_data_row("SHOW TABLES LIKE '{$dbprefix}datalists'"); if (!$exists) { // need to return true to let upgrade includer know all is fine return true; } $duplicates = get_data("SELECT name\n\tFROM {$dbprefix}datalists\n\tWHERE name IN (SELECT name FROM {$dbprefix}config)\n\tAND name NOT IN ('processed_upgrades', 'version')\n"); if (!empty($duplicates)) { $duplicates_array = []; foreach ($duplicates as $duplicate) { $duplicates_array[] = $duplicate->name; } $duplicates = implode(', ', $duplicates_array); throw new \DatabaseException("Found names ({$duplicates}) in datalist that also exist in config. Don't know how to merge."); } $rows = get_data("SELECT * FROM {$dbprefix}datalists"); foreach ($rows as $row) { $value = $row->value; if (in_array($row->name, ['version', 'processed_upgrades'])) { // do not copy name to config as during upgrades this is already taken care of by the upgrade process continue; } elgg_save_config($row->name, $value); } // all data migrated, so drop the table delete_data("DROP TABLE {$dbprefix}datalists");
} $order = array(); $remove_settings = array(); // make sure we have a name and type foreach ($settings as $k => $v) { if (!preg_match('/admin_defined_profile_([0-9]+)/i', $k, $matches)) { continue; } $i = $matches[1]; $type_name = "admin_defined_profile_type_{$i}"; $type = elgg_extract($type_name, $settings, null); if ($type) { // field name elgg_save_config($k, $v); // field value elgg_save_config($type_name, $type); $order[] = $i; $remove_settings[] = $k; $remove_settings[] = $type_name; } } if ($order) { // these will always need to be in order, but there might be gaps ksort($order); $order_str = implode(',', $order); elgg_save_config('profile_custom_fields', $order_str); foreach ($remove_settings as $name) { $plugin->unsetSetting($name); } $plugin->unsetSetting('user_defined_fields'); }
<?php /** * Configure site maintenance mode */ $mode = (int) get_input('mode'); $message = get_input('message'); $site = elgg_get_site_entity(); $result = elgg_save_config('elgg_maintenance_mode', $mode, null); $result = $result && $site->setPrivateSetting('elgg_maintenance_message', $message); if ($result) { system_message(elgg_echo('admin:maintenance_mode:saved')); } else { register_error(elgg_echo('save:fail')); }
<?php /** * Set default access for older sites */ $access = elgg_get_config('default_access'); if ($access == false) { elgg_save_config('default_access', ACCESS_LOGGED_IN); }
<?php /** * Save the developer settings */ $site = elgg_get_site_entity(); if (get_input('simple_cache')) { elgg_enable_simplecache(); } else { elgg_disable_simplecache(); } if (get_input('system_cache')) { elgg_enable_system_cache(); } else { elgg_disable_system_cache(); } $debug = get_input('debug_level'); if ($debug) { elgg_save_config('debug', $debug); } else { elgg_remove_config('debug'); } $simple_settings = ['display_errors', 'screen_log', 'show_strings', 'wrap_views', 'log_events', 'show_gear', 'show_modules']; foreach ($simple_settings as $setting) { elgg_set_plugin_setting($setting, get_input($setting), 'developers'); } elgg_flush_caches(); system_message(elgg_echo('developers:settings:success')); forward(REFERER);
function loginrequired_init() { elgg_extend_view('css/elgg', 'loginrequired/css'); if (elgg_get_config('default_access') == ACCESS_PUBLIC) { elgg_save_config('default_access', ACCESS_LOGGED_IN); } elgg_register_plugin_hook_handler('access:collections:write', 'all', 'loginrequired_remove_public_access', 9999); // No need to do all the checking below if the user is already logged in... performance is key :) if (elgg_is_logged_in()) { return; } elgg_unextend_view('page/elements/header', 'search/header'); if (elgg_is_active_plugin('aalborg_theme')) { elgg_register_plugin_hook_handler('view', 'page/elements/navbar', 'suppress_aalborg_theme_navbar'); } elgg_register_page_handler('', 'loginrequired_index'); elgg_register_plugin_hook_handler('login_required', 'login_required', 'login_required_default_allowed_list'); // Get the current page URL without any ? & parameters... this is required for the registration page to work properly $current_url = current_page_url(); $parameters_start = strrpos($current_url, '?'); if ($parameters_start) { $current_url = substr($current_url, 0, $parameters_start); } // Always allow index page if ($current_url == elgg_get_site_url()) { return; } $allow = array(); // Allow should have pages $allow[] = '_graphics'; $allow[] = 'walled_garden/.*'; $allow[] = 'action/.*'; $allow[] = 'login'; $allow[] = 'register'; $allow[] = 'forgotpassword'; $allow[] = 'changepassword'; $allow[] = 'refresh_token'; $allow[] = 'ajax/view/js/languages'; $allow[] = 'ajax/view/languages.js'; $allow[] = 'upgrade\\.php'; $allow[] = 'xml-rpc\\.php'; $allow[] = 'mt/mt-xmlrpc\\.cgi'; $allow[] = 'css/.*'; $allow[] = 'js/.*'; $allow[] = 'cache/[0-9]+/\\w+/.*'; $allow[] = 'cache/[0-9]+/\\w+/js|css/.*'; $allow[] = 'cron/.*'; $allow[] = 'services/.*'; // Allow other plugin developers to edit the array values $add_allow = elgg_trigger_plugin_hook('login_required', 'login_required'); // If more URL's are added... merge both with original list if (is_array($add_allow)) { $allow = array_merge($allow, $add_allow); } // Any public_pages defined via Elgg's walled garden plugin hook? $plugins = elgg_trigger_plugin_hook('public_pages', 'walled_garden', null, array()); // If more URL's are added... merge both with original list if (is_array($plugins)) { $allow = array_merge($allow, $plugins); } // Check if current page is in allowed list... otherwise redirect to login foreach ($allow as $public) { $pattern = "`^" . elgg_get_site_url() . $public . "/*\$`i"; if (preg_match($pattern, $current_url)) { return; } } elgg_gatekeeper(); }
<?php $settings = ['security_protect_upgrade', 'security_protect_cron', 'security_disable_password_autocomplete', 'security_email_require_password', 'security_notify_admins', 'security_notify_user_admin', 'security_notify_user_ban', 'security_notify_user_password']; foreach ($settings as $setting) { elgg_save_config($setting, (bool) get_input($setting)); } system_message(elgg_echo('admin:configuration:success')); forward(REFERER);
} elgg_save_config('default_access', (int) get_input('default_access', ACCESS_PRIVATE)); $user_default_access = 'on' === get_input('allow_user_default_access'); elgg_save_config('allow_user_default_access', $user_default_access); $debug = get_input('debug'); if ($debug) { elgg_save_config('debug', $debug); } else { elgg_remove_config('debug'); } // allow new user registration? $allow_registration = 'on' === get_input('allow_registration', false); elgg_save_config('allow_registration', $allow_registration); // setup walled garden $walled_garden = 'on' === get_input('walled_garden', false); elgg_save_config('walled_garden', $walled_garden); $regenerate_site_secret = get_input('regenerate_site_secret', false); if ($regenerate_site_secret) { // if you cancel this even you should present a message to the user if (elgg_trigger_before_event('regenerate_site_secret', 'system')) { init_site_secret(); elgg_reset_system_cache(); elgg_trigger_after_event('regenerate_site_secret', 'system'); system_message(elgg_echo('admin:site:secret_regenerated')); elgg_delete_admin_notice('weak_site_key'); } } if ($site->save()) { system_message(elgg_echo("admin:configuration:success")); } else { register_error(elgg_echo("admin:configuration:fail"));
<?php /** * Elgg 1.8-svn upgrade 2011021800 * goodbye_walled_garden * * Removes the Walled Garden plugin in favor of new system settings */ global $CONFIG; $access = elgg_set_ignore_access(TRUE); if (elgg_is_active_plugin('walledgarden')) { disable_plugin('walledgarden'); set_config('allow_registration', FALSE); set_config('walled_garden', TRUE); } else { set_config('allow_registration', TRUE); set_config('walled_garden', FALSE); } // this was for people who manually set the config option $disable_registration = elgg_get_config('disable_registration'); if ($disable_registration !== null) { $allow_registration = !$disable_registration; elgg_save_config('allow_registration', $allow_registration); $site = elgg_get_site_entity(); $query = "DELETE FROM {$CONFIG->dbprefix}config\n\t\t\t\tWHERE name = 'disable_registration' AND site_guid = {$site->guid}"; delete_data($query); } elgg_set_ignore_access($access);
/** * Updates the basic settings for the primary site object. * * Basic site settings are saved as metadata on the site object, * with the exception of the default language, which is saved in * the config table. * * @package Elgg.Core * @subpackage Administration.Site */ $site = elgg_get_site_entity(); if (!$site) { throw new InstallationException("The system is missing an ElggSite entity!"); } if (!$site instanceof ElggSite) { throw new InstallationException("Passing a non-ElggSite to an ElggSite constructor!"); } $site->description = get_input('sitedescription'); $site->name = strip_tags(get_input('sitename')); $site->email = get_input('siteemail'); $site->save(); elgg_save_config('language', get_input('language')); $default_limit = (int) get_input('default_limit'); if ($default_limit < 1) { register_error(elgg_echo('admin:configuration:default_limit')); forward(REFERER); } elgg_save_config('default_limit', $default_limit); system_message(elgg_echo('admin:configuration:success')); forward(REFERER);
<?php /** * Elgg profile plugin edit default profile action removal * */ $id = get_input('id'); $fieldlist = elgg_get_config('profile_custom_fields'); if (!$fieldlist) { $fieldlist = ''; } $fieldlist = str_replace("{$id},", "", $fieldlist); $fieldlist = str_replace(",{$id}", "", $fieldlist); $fieldlist = str_replace("{$id}", "", $fieldlist); if ($id && unset_config("admin_defined_profile_{$id}") && unset_config("admin_defined_profile_type_{$id}") && elgg_save_config('profile_custom_fields', $fieldlist)) { system_message(elgg_echo('profile:editdefault:delete:success')); } else { register_error(elgg_echo('profile:editdefault:delete:fail')); } forward(REFERER);
public function testElggGetConfigNonCurrentSiteConfig() { $name = 'foo' . rand(0, 1000); $value = 'test'; $this->assertTrue(elgg_save_config($name, $value, 17)); $this->assertIdentical($value, elgg_get_config($name, 17)); $this->assertTrue(unset_config($name, 17)); }
<?php /** * Save menu items. * * @package Elgg * @subpackage Core */ // featured menu items $featured_names = get_input('featured_menu_names', array()); $featured_names = array_unique($featured_names); if (in_array(' ', $featured_names)) { unset($featured_names[array_search(' ', $featured_names)]); } elgg_save_config('site_featured_menu_names', $featured_names); // custom menu items $custom_menu_titles = get_input('custom_menu_titles', array()); $custom_menu_urls = get_input('custom_menu_urls', array()); $num_menu_items = count($custom_menu_titles); $custom_menu_items = array(); for ($i = 0; $i < $num_menu_items; $i++) { if (trim($custom_menu_urls[$i]) && trim($custom_menu_titles[$i])) { $url = $custom_menu_urls[$i]; $title = $custom_menu_titles[$i]; $custom_menu_items[$title] = $url; } } elgg_save_config('site_custom_menu_items', $custom_menu_items); system_message(elgg_echo('admin:menu_items:saved')); forward(REFERER);
/** * Add or update a config setting. * * Plugin authors should use elgg_set_config(). * * If the config name already exists, it will be updated to the new value. * * @internal These settings are stored in the dbprefix_config table and read * during system boot into $CONFIG. * * @internal The value is serialized so we maintain type information. * * @param string $name The name of the configuration value * @param mixed $value Its value * * @return bool * @see unset_config() * @see get_config() * @access private * * @deprecated Use elgg_save_config() */ function set_config($name, $value) { elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_save_config().', '3.0'); return elgg_save_config($name, $value); }
<?php /** * Elgg profile plugin reorder fields * */ $ordering = get_input('fieldorder'); $result = elgg_save_config('profile_custom_fields', $ordering); // called by ajax so we exit exit;