[44] | 1 | <?php
|
---|
| 2 | /**
|
---|
| 3 | * Copyright 2006, 2007, 2008, 2009 Eric D. Hough (http://ehough.com)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of TubePress (http://tubepress.org)
|
---|
| 6 | *
|
---|
| 7 | * TubePress is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * TubePress is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with TubePress. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | *
|
---|
| 20 | */
|
---|
| 21 |
|
---|
| 22 | function_exists('tubepress_load_classes')
|
---|
| 23 | || require(dirname(__FILE__) . '/../../../../tubepress_classloader.php');
|
---|
| 24 | tubepress_load_classes(array('org_tubepress_options_manager_OptionsManager',
|
---|
| 25 | 'org_tubepress_options_storage_StorageManager',
|
---|
| 26 | 'org_tubepress_options_reference_OptionsReference',
|
---|
| 27 | 'org_tubepress_options_validation_InputValidationService'));
|
---|
| 28 |
|
---|
| 29 | /**
|
---|
| 30 | * Holds the current options for TubePress. This is the default options,
|
---|
| 31 | * usually in persistent storage somewhere, and custom options parsed
|
---|
| 32 | * from a shortcode
|
---|
| 33 | */
|
---|
| 34 | class org_tubepress_options_manager_SimpleOptionsManager implements org_tubepress_options_manager_OptionsManager
|
---|
| 35 | {
|
---|
| 36 | /**
|
---|
| 37 | * Enter description here...
|
---|
| 38 | *
|
---|
| 39 | * @var array
|
---|
| 40 | */
|
---|
| 41 | private $_customOptions = array();
|
---|
| 42 |
|
---|
| 43 | /**
|
---|
| 44 | * Enter description here...
|
---|
| 45 | *
|
---|
| 46 | * @var org_tubepress_options_storage_StorageManager
|
---|
| 47 | */
|
---|
| 48 | private $_tpsm;
|
---|
| 49 |
|
---|
| 50 | private $_optionsReference;
|
---|
| 51 |
|
---|
| 52 | private $_validationService;
|
---|
| 53 |
|
---|
| 54 | /**
|
---|
| 55 | * The shortcode currently in use
|
---|
| 56 | *
|
---|
| 57 | * @var string
|
---|
| 58 | */
|
---|
| 59 | private $_shortcode;
|
---|
| 60 |
|
---|
| 61 | /**
|
---|
| 62 | * Gets the value of an option
|
---|
| 63 | *
|
---|
| 64 | * @param string $optionName The name of the option
|
---|
| 65 | *
|
---|
| 66 | * @return unknown The option value
|
---|
| 67 | */
|
---|
| 68 | public function get($optionName)
|
---|
| 69 | {
|
---|
| 70 | /* get the value, either from the shortcode or the db */
|
---|
| 71 | $value = array_key_exists($optionName, $this->_customOptions) ?
|
---|
| 72 | $this->_customOptions[$optionName] : $this->_tpsm->get($optionName);
|
---|
| 73 |
|
---|
| 74 | /* get a valid value for this option */
|
---|
| 75 | try {
|
---|
| 76 | $this->_validationService->validate($optionName, $value);
|
---|
| 77 | } catch (Exception $e) {
|
---|
| 78 | $value = $this->_optionsReference->getDefaultValue($optionName);
|
---|
| 79 | }
|
---|
| 80 | return $value;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | /**
|
---|
| 84 | * Enter description here...
|
---|
| 85 | *
|
---|
| 86 | * @param array $customOpts Custom options
|
---|
| 87 | *
|
---|
| 88 | * @return void
|
---|
| 89 | */
|
---|
| 90 | public function setCustomOptions($customOpts)
|
---|
| 91 | {
|
---|
| 92 | $this->_customOptions = $customOpts;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | public function mergeCustomOptions($customOpts)
|
---|
| 96 | {
|
---|
| 97 | $this->_customOptions = array_merge($this->_customOptions, $customOpts);
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | /**
|
---|
| 101 | * Enter description here...
|
---|
| 102 | *
|
---|
| 103 | * @param string $newTagString The new shortcode
|
---|
| 104 | *
|
---|
| 105 | * @return void
|
---|
| 106 | */
|
---|
| 107 | public function setShortcode($newTagString)
|
---|
| 108 | {
|
---|
| 109 | $this->_shortcode = $newTagString;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | /**
|
---|
| 113 | * Enter description here...
|
---|
| 114 | *
|
---|
| 115 | * @return string The full shortcode
|
---|
| 116 | */
|
---|
| 117 | public function getShortcode()
|
---|
| 118 | {
|
---|
| 119 | return $this->_shortcode;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | public function setStorageManager(org_tubepress_options_storage_StorageManager $tpsm)
|
---|
| 123 | {
|
---|
| 124 | $this->_tpsm = $tpsm;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | public function setOptionsReference(org_tubepress_options_reference_OptionsReference $ref)
|
---|
| 128 | {
|
---|
| 129 | $this->_optionsReference = $ref;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | public function setValidationService(org_tubepress_options_validation_InputValidationService $valService)
|
---|
| 133 | {
|
---|
| 134 | $this->_validationService = $valService;
|
---|
| 135 | }
|
---|
| 136 | }
|
---|