1: <?php
2:
3: 4: 5:
6: class Quform_Options
7: {
8: 9: 10: 11: 12:
13: protected $key;
14:
15: 16: 17: 18: 19:
20: protected $options = array();
21:
22: public function __construct($key)
23: {
24: $this->key = $key;
25:
26: $options = get_option($this->key);
27:
28: if ( ! is_array($options)) {
29: $options = $this->getDefaults();
30: }
31:
32: $this->options = $options;
33: }
34:
35: 36: 37: 38: 39:
40: protected function getDefaults()
41: {
42: return array(
43: 'defaultEmailAddress' => get_bloginfo('admin_email'),
44: 'defaultEmailName' => '',
45: 'defaultFromEmailAddress' => 'wordpress@' . preg_replace('/^www./', '', Quform::get($_SERVER, 'SERVER_NAME')),
46: 'defaultFromEmailName' => get_bloginfo('name'),
47: 'licenseKey' => '',
48: 'locale' => 'en-US',
49: 'dateFormatJs' => '',
50: 'timeFormatJs' => '',
51: 'dateTimeFormatJs' => '',
52: 'dateFormat' => '',
53: 'timeFormat' => '',
54: 'dateTimeFormat' => '',
55: 'rtl' => '',
56: 'recaptchaSiteKey' => '',
57: 'recaptchaSecretKey' => '',
58: 'hcaptchaSiteKey' => '',
59: 'hcaptchaSecretKey' => '',
60: 'turnstileSiteKey' => '',
61: 'turnstileSecretKey' => '',
62: 'customCss' => '',
63: 'customCssTablet' => '',
64: 'customCssPhone' => '',
65: 'customJs' => '',
66: 'loadScripts' => 'always',
67: 'loadScriptsCustom' => array(),
68: 'disabledStyles' => array(
69: 'fontAwesome' => false,
70: 'select2' => false,
71: 'qtip' => false,
72: 'fancybox' => false,
73: 'fancybox2' => false,
74: 'fancybox3' => false,
75: 'magnificPopup' => false
76: ),
77: 'disabledScripts' => array(
78: 'fileUpload' => false,
79: 'scrollTo' => false,
80: 'select2' => false,
81: 'qtip' => false,
82: 'fancybox' => false,
83: 'fancybox2' => false,
84: 'fancybox3' => false,
85: 'magnificPopup' => false,
86: 'infieldLabels' => false,
87: 'datepicker' => false,
88: 'timepicker' => false
89: ),
90: 'combineCss' => true,
91: 'combineJs' => true,
92: 'popupEnabled' => false,
93: 'popupScript' => 'fancybox-2',
94: 'rawFix' => false,
95: 'scrollOffset' => '50',
96: 'scrollSpeed' => '800',
97: 'allowAllFileTypes' => false,
98: 'showEditLink' => true,
99: 'csrfProtection' => true,
100: 'timeBasedProtection' => true,
101: 'supportPageCaching' => true,
102: 'toolbarMenu' => true,
103: 'dashboardWidget' => true,
104: 'insertFormButton' => true,
105: 'preventFouc' => false,
106: 'secureApiRequests' => true,
107: 'saveEntries' => true,
108: 'saveIpAddresses' => true,
109: 'alwaysShowFullDates' => false,
110: 'referralEnabled' => false,
111: 'referralText' => __('Powered by Quform', 'quform'),
112: 'referralLink' => '',
113: 'activeThemes' => array(),
114: 'activeLocales' => array(),
115: 'activeDatepickers' => array(),
116: 'activeTimepickers' => array(),
117: 'activeEnhancedUploaders' => array(),
118: 'activeEnhancedSelects' => array(),
119: 'activeCustomCss' => array(),
120: 'inactiveCustomCss' => array(),
121: 'cacheBuster' => time()
122: );
123: }
124:
125: 126: 127:
128: protected function update()
129: {
130: update_option($this->key, $this->options);
131: }
132:
133: 134: 135: 136: 137: 138: 139: 140: 141: 142:
143: public function get($key, $default = null)
144: {
145: $value = Quform::get($this->options, $key, $default);
146:
147: if ($value === null) {
148: $value = Quform::get($this->getDefaults(), $key, $default);
149: }
150:
151: return apply_filters("quform_get_option_$key", $value, $default);
152: }
153:
154: 155: 156: 157: 158: 159:
160: public function set($key, $value = null)
161: {
162: if (is_array($key)) {
163: foreach ($key as $k => $v) {
164: $this->options[$k] = $v;
165: }
166: } else {
167: $this->options[$key] = $value;
168: }
169:
170: $this->update();
171: }
172:
173: 174: 175: 176: 177:
178: public function getLocale() {
179: return apply_filters('quform_locale', $this->get('locale'));
180: }
181:
182: 183: 184: 185: 186: 187: 188: 189:
190: public function formatDate($datetime, $hideDateIfSameDay = false, $customDateFormat = '')
191: {
192: if ( ! Quform::isNonEmptyString($datetime)) {
193: return '';
194: }
195:
196: try {
197: $date = new DateTime($datetime, new DateTimeZone('UTC'));
198:
199: if (Quform::isNonEmptyString($customDateFormat)) {
200: return Quform::date($customDateFormat, $date);
201: }
202:
203: if ($this->get('alwaysShowFullDates')) {
204: $hideDateIfSameDay = false;
205: }
206:
207: $today = new DateTime('now', new DateTimeZone('UTC'));
208:
209: if ($hideDateIfSameDay && $date->format('Y-m-d') == $today->format('Y-m-d')) {
210: $key = 'timeFormat';
211: } else {
212: $key = 'dateTimeFormat';
213: }
214:
215: $format = $this->get($key);
216:
217: if ( ! Quform::isNonEmptyString($format)) {
218: $locale = Quform::getLocale($this->getLocale());
219: $format = $locale[$key];
220: }
221:
222: return Quform::date($format, $date);
223: } catch (Exception $e) {
224: return '';
225: }
226: }
227:
228: 229: 230:
231: public function uninstall()
232: {
233:
234: delete_option($this->key);
235: }
236: }
237: