return $a[$key]; } return null; } /** * Returns string value */ public function get_string( $key, $default = '', $trim = true ) { $value = (string)$this->get( $key, $default ); return $trim ? trim( $value ) : $value; } /** * Returns integer value */ public function get_integer( $key, $default = 0 ) { return (integer)$this->get( $key, $default ); } /** * Returns boolean value */ public function get_boolean( $key, $default = false ) { return (boolean)$this->get( $key, $default ); } /** * Returns array value */ public function get_array( $key, $default = array() ) { return (array)$this->get( $key, $default ); } /** * Returns config value with ability to hook it. * Should be called only when filters already loaded and * call doesn't repeat too many times */ public function getf( $key, $default = null ) { $v = $this->get( $key, $default ); return apply_filters( 'w3tc_config_item_' . $key, $v ); } /** * Returns string value with ability to hook it */ public function getf_string( $key, $default = '', $trim = true ) { $value = (string)$this->getf( $key, $default ); return $trim ? trim( $value ) : $value; } /** * Returns integer value with ability to hook it */ public function getf_integer( $key, $default = 0 ) { return (integer)$this->getf( $key, $default ); } /** * Returns boolean value ability to hook it */ public function getf_boolean( $key, $default = false ) { return (boolean)$this->getf( $key, $default ); } /** * Returns array value ability to hook it */ public function getf_array( $key, $default = array() ) { return (array)$this->getf( $key, $default ); } /** * Check if an extension is active */ public function is_extension_active( $extension ) { $extensions = $this->get_array( 'extensions.active' ); return isset( $extensions[$extension] ); } public function is_extension_active_frontend( $extension ) { $extensions = $this->get_array( 'extensions.active_frontend' ); return isset( $extensions[$extension] ); } public function set_extension_active_frontend( $extension, $is_active_frontend ) { $a = $this->get_array( 'extensions.active_frontend' ); if ( !$is_active_frontend ) { unset( $a[$extension] ); } else { $a[$extension] = '*'; } $this->set( 'extensions.active_frontend', $a ); } public function set_extension_active_dropin( $extension, $is_active_dropin ) { $a = $this->get_array( 'extensions.active_dropin' ); if ( !$is_active_dropin ) { unset( $a[$extension] ); } else { $a[$extension] = '*'; } $this->set( 'extensions.active_dropin', $a ); } /** * Sets config value. * Method to override */ public function set( $key, $value ) { if ( !is_array( $key ) ) { $this->_data[$key] = $value; } else { // set extension's key $key0 = $key[0]; $key1 = $key[1]; if ( !isset( $this->_data[$key0] ) || !is_array( $this->_data[$key0] ) ) $this->_data[$key0] = array(); $this->_data[$key0][$key1] = $value; } return $value; } /** * Check if we are in preview mode */ public function is_preview() { return $this->_preview; } /** * Returns true if we edit master config */ public function is_master() { return $this->_is_master; } public function is_compiled() { return $this->_compiled; } /** * Sets default values */ public function set_defaults() { $c = new ConfigCompiler( $this->_blog_id, $this->_preview ); $this->_data = $c->get_data(); } /** * Saves modified config */ public function save() { if ( function_exists( 'do_action' ) ) do_action( 'w3tc_config_save', $this ); $c = new ConfigCompiler( $this->_blog_id, $this->_preview ); $c->apply_data( $this->_data ); $c->save(); } public function is_sealed( $key ) { if ( $this->is_master() ) return false; // better to use master config data here, but // its faster and preciese enough for UI return ConfigCompiler::child_key_sealed( $key, $this->_data, $this->_data ); } /** * Exports config content */ public function export() { if ( defined( 'JSON_PRETTY_PRINT' ) ) $content = json_encode( $this->_data, JSON_PRETTY_PRINT ); else $content = json_encode( $this->_data ); return $content; } /** * Imports config content */ public function import( $filename ) { if ( file_exists( $filename ) && is_readable( $filename ) ) { $content = file_get_contents( $filename ); if ( substr( $content, 0, 14 ) == '