public function save() { $data = array('version' => $this->_data['version']); if ($this->is_master()) { foreach ($this->_data as $key => $value) { $data[$key] = $this->_data[$key]; } } else { // write only overwrited keys $master = new ConfigCompiler(0, $this->_preview); $master->load(); foreach ($this->_data as $key => $value) { if (!ConfigCompiler::child_key_sealed($key, $master->_data, $this->_data)) { $data[$key] = $this->_data[$key]; } } } $filename = Config::util_config_filename($this->_blog_id, $this->_preview); if (defined('JSON_PRETTY_PRINT')) { $config = json_encode($data, JSON_PRETTY_PRINT); } else { // for older php versions $config = json_encode($data); } Util_File::file_put_contents_atomic($filename, $config); }
/** * Registers new blog url in url=>blog mapfile */ public static function register_new_item($blog_home_url, $config) { if (!isset($GLOBALS['current_blog'])) { return false; } $filename = Util_WpmuBlogmap::blogmap_filename_by_home_url($blog_home_url); if (!@file_exists($filename)) { $blog_ids = array(); } else { $data = @file_get_contents($filename); $blog_ids = @json_decode($data, true); if (!is_array($blog_ids)) { $blog_ids = array(); } } if (isset($blog_ids[$blog_home_url])) { return false; } $data = $config->get_boolean('common.force_master') ? 'm' : 'c'; $blog_home_url = preg_replace('/[^a-zA-Z0-9\\+\\.%~!()\\/\\-\\_]/', '', $blog_home_url); $blog_ids[$blog_home_url] = $data . $GLOBALS['current_blog']->blog_id; $data = json_encode($blog_ids); try { Util_File::file_put_contents_atomic($filename, $data); } catch (\Exception $ex) { return false; } unset(self::$content_by_filename[$filename]); return true; }