broken-link-checker
Last commit date
images
17 years ago
languages
16 years ago
JSON.php
17 years ago
broken-link-checker.php
16 years ago
config-manager.php
16 years ago
core.php
16 years ago
highlighter-class.php
16 years ago
instance-classes.php
16 years ago
link-classes.php
16 years ago
readme.txt
16 years ago
uninstall.php
16 years ago
utility-class.php
16 years ago
config-manager.php
88 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @author W-Shadow |
| 5 | * @copyright 2009 |
| 6 | */ |
| 7 | |
| 8 | if ( !class_exists('blcConfigurationManager') ){ |
| 9 | |
| 10 | class blcConfigurationManager { |
| 11 | |
| 12 | var $option_name; |
| 13 | |
| 14 | var $options; |
| 15 | var $defaults; |
| 16 | var $loaded_values; |
| 17 | |
| 18 | function blcConfigurationManager( $option_name = '', $default_settings = null ){ |
| 19 | $this->option_name = $option_name; |
| 20 | |
| 21 | if ( is_array($default_settings) ){ |
| 22 | $this->defaults = $default_settings; |
| 23 | } else { |
| 24 | $this->defaults = array(); |
| 25 | } |
| 26 | $this->loaded_values = array(); |
| 27 | |
| 28 | $this->options = $this->defaults; |
| 29 | |
| 30 | if ( !empty( $this->option_name ) ) |
| 31 | $this->load_options(); |
| 32 | } |
| 33 | |
| 34 | function set_defaults( $default_settings = null ){ |
| 35 | if ( is_array($default_settings) ){ |
| 36 | $this->defaults = array(); |
| 37 | } else { |
| 38 | $this->defaults = $default_settings; |
| 39 | } |
| 40 | $this->options = array_merge($this->defaults, $this->loaded_values); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * blcOptionManager::load_options() |
| 45 | * Load plugin options from the database. The current $options values are not affected |
| 46 | * if this function fails. |
| 47 | * |
| 48 | * @param string $option_name |
| 49 | * @return bool True if options were loaded, false otherwise. |
| 50 | */ |
| 51 | function load_options( $option_name = '' ){ |
| 52 | if ( !empty($option_name) ){ |
| 53 | $this->option_name = $option_name; |
| 54 | } |
| 55 | |
| 56 | if ( empty($this->option_name) ) return false; |
| 57 | |
| 58 | $new_options = get_option($this->option_name); |
| 59 | if( !is_array( $new_options ) ){ |
| 60 | return false; |
| 61 | } else { |
| 62 | $this->loaded_values = $new_options; |
| 63 | $this->options = array_merge( $this->defaults, $this->loaded_values ); |
| 64 | return true; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * blcOptionManager::save_options() |
| 70 | * Save plugin options to the databse. |
| 71 | * |
| 72 | * @param string $option_name (Optional) Save the options under this name |
| 73 | * @return bool True on success, false on failure |
| 74 | */ |
| 75 | function save_options( $option_name = '' ){ |
| 76 | if ( !empty($option_name) ){ |
| 77 | $this->option_name = $option_name; |
| 78 | } |
| 79 | |
| 80 | if ( empty($this->option_name) ) return false; |
| 81 | |
| 82 | update_option( $this->option_name, $this->options ); |
| 83 | return true; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | } |
| 88 | ?> |