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:             'supportPageCaching' => true,
101:             'toolbarMenu' => true,
102:             'dashboardWidget' => true,
103:             'insertFormButton' => true,
104:             'preventFouc' => false,
105:             'secureApiRequests' => true,
106:             'saveEntries' => true,
107:             'saveIpAddresses' => true,
108:             'alwaysShowFullDates' => false,
109:             'referralEnabled' => false,
110:             'referralText' => __('Powered by Quform', 'quform'),
111:             'referralLink' => '',
112:             'activeThemes' => array(),
113:             'activeLocales' => array(),
114:             'activeDatepickers' => array(),
115:             'activeTimepickers' => array(),
116:             'activeEnhancedUploaders' => array(),
117:             'activeEnhancedSelects' => array(),
118:             'activeCustomCss' => array(),
119:             'inactiveCustomCss' => array(),
120:             'cacheBuster' => time()
121:         );
122:     }
123: 
124:     125: 126: 
127:     protected function update()
128:     {
129:         update_option($this->key, $this->options);
130:     }
131: 
132:     133: 134: 135: 136: 137: 138: 139: 140: 141: 
142:     public function get($key, $default = null)
143:     {
144:         $value = Quform::get($this->options, $key, $default);
145: 
146:         if ($value === null) {
147:             $value = Quform::get($this->getDefaults(), $key, $default);
148:         }
149: 
150:         return apply_filters("quform_get_option_$key", $value, $default);
151:     }
152: 
153:     154: 155: 156: 157: 158: 
159:     public function set($key, $value = null)
160:     {
161:         if (is_array($key)) {
162:             foreach ($key as $k => $v) {
163:                 $this->options[$k] = $v;
164:             }
165:         } else {
166:             $this->options[$key] = $value;
167:         }
168: 
169:         $this->update();
170:     }
171: 
172:     173: 174: 175: 176: 
177:     public function getLocale() {
178:         return apply_filters('quform_locale', $this->get('locale'));
179:     }
180: 
181:     182: 183: 184: 185: 186: 187: 188: 
189:     public function formatDate($datetime, $hideDateIfSameDay = false, $customDateFormat = '')
190:     {
191:         if ( ! Quform::isNonEmptyString($datetime)) {
192:             return '';
193:         }
194: 
195:         try {
196:             $date = new DateTime($datetime, new DateTimeZone('UTC'));
197: 
198:             if (Quform::isNonEmptyString($customDateFormat)) {
199:                 return Quform::date($customDateFormat, $date);
200:             }
201: 
202:             if ($this->get('alwaysShowFullDates')) {
203:                 $hideDateIfSameDay = false;
204:             }
205: 
206:             $today = new DateTime('now', new DateTimeZone('UTC'));
207: 
208:             if ($hideDateIfSameDay && $date->format('Y-m-d') == $today->format('Y-m-d')) {
209:                 $key = 'timeFormat';
210:             } else {
211:                 $key = 'dateTimeFormat';
212:             }
213: 
214:             $format = $this->get($key);
215: 
216:             if ( ! Quform::isNonEmptyString($format)) {
217:                 $locale = Quform::getLocale($this->getLocale());
218:                 $format = $locale[$key];
219:             }
220: 
221:             return Quform::date($format, $date);
222:         } catch (Exception $e) {
223:             return '';
224:         }
225:     }
226: 
227:     228: 229: 
230:     public function uninstall()
231:     {
232:         
233:         delete_option($this->key);
234:     }
235: }
236: