1: <?php
2:
3: 4: 5:
6: class Quform_Admin_Page_Settings extends Quform_Admin_Page
7: {
8: 9: 10:
11: protected $options;
12:
13: 14: 15:
16: protected $license;
17:
18: 19: 20:
21: protected $permissions;
22:
23: 24: 25:
26: protected $scriptLoader;
27:
28: 29: 30: 31: 32: 33: 34: 35:
36: public function __construct(Quform_ViewFactory $viewFactory, Quform_Repository $repository,
37: Quform_Options $options, Quform_License $license,
38: Quform_Permissions $permissions, Quform_ScriptLoader $scriptLoader)
39: {
40: parent::__construct($viewFactory, $repository);
41:
42: $this->options = $options;
43: $this->license = $license;
44: $this->permissions = $permissions;
45: $this->viewFactory = $viewFactory;
46: $this->scriptLoader = $scriptLoader;
47: }
48:
49: public function init()
50: {
51: $this->template = QUFORM_TEMPLATE_PATH . '/admin/settings.php';
52: }
53:
54: 55: 56:
57: protected function enqueueStyles()
58: {
59: wp_enqueue_style('qtip2', Quform::url('css/jquery.qtip.min.css'), array(), '3.0.4');
60: wp_enqueue_style('quform-select2', Quform::url('css/select2.min.css'), array(), '4.0.13');
61:
62: parent::enqueueStyles();
63: }
64:
65: 66: 67:
68: protected function enqueueScripts()
69: {
70: parent::enqueueScripts();
71:
72: wp_enqueue_script('qtip2', Quform::url('js/jquery.qtip.min.js'), array('jquery'), '3.0.4', true);
73: wp_enqueue_script('quform-select2', Quform::url('js/select2.min.js'), array('jquery'), '4.0.13', true);
74: wp_enqueue_script('themecatcher-tabs', Quform::adminUrl('js/tc.tabs.min.js'), array('jquery'), '1.0.0', true);
75: wp_enqueue_script('quform-settings', Quform::adminUrl('js/settings.min.js'), array('jquery'), QUFORM_VERSION, true);
76:
77: wp_localize_script('quform-settings', 'quformSettingsL10n', array(
78: 'verifyNonce' => wp_create_nonce('quform_verify_purchase_code'),
79:
80: 'errorVerifying' => sprintf(__('An error occurred verifying the license key, please try again. If this problem persists, see %1$sthis page%2$s.', 'quform'), '<a href="https://support.themecatcher.net/quform-wordpress-v2/troubleshooting/common-problems/an-error-occurred-verifying-the-license-key" target="_blank">', '</a>'),
81: 'waitVerifying' => __('Please wait, verification in progress', 'quform'),
82: 'valid' => __('Valid', 'quform'),
83: 'bundled' => __('Valid (bundled)', 'quform'),
84: 'unlicensed' => __('Unlicensed', 'quform'),
85: 'updateCheckNonce' => wp_create_nonce('quform_manual_update_check'),
86: 'errorCheckingForUpdate' => __('An error occurred checking for an update.', 'quform'),
87: 'waitUpdating' => __('Please wait, checking for an update', 'quform'),
88: 'saveSettingsNonce' => wp_create_nonce('quform_save_settings'),
89: 'settingsSaved' => __('Settings saved', 'quform'),
90: 'errorSavingSettings' => __('An error occurred saving the settings.', 'quform'),
91: 'rebuildScriptCacheNonce' => wp_create_nonce('quform_rebuild_script_cache'),
92: 'errorRebuildingScriptCache' => __('An error occurred rebuilding the script cache.', 'quform'),
93: 'scriptCacheRebuilt' => __('Script cache rebuilt', 'quform'),
94: 'searchPostsNonce' => wp_create_nonce('quform_settings_search_posts')
95: ));
96: }
97:
98: 99: 100: 101: 102: 103: 104:
105: public function getNavHtml(array $currentForm = null, array $extra = array())
106: {
107: ob_start();
108: ?>
109: <div class="qfb-nav-item qfb-nav-page-info"><i class="qfb-nav-page-icon qfb-mdi qfb-mdi-settings"></i><span class="qfb-nav-page-title"><?php esc_html_e('Settings', 'quform'); ?></span></div>
110: <?php
111:
112: return parent::getNavHtml($currentForm, array(40 => ob_get_clean()));
113: }
114:
115: 116: 117:
118: public function process()
119: {
120: if ( ! current_user_can('quform_settings')) {
121: wp_die(__( 'You do not have sufficient permissions to access this page.', 'quform'), 403);
122: }
123:
124: global $wp_roles;
125:
126: $this->view->with(array(
127: 'options' => $this->options,
128: 'license' => $this->license,
129: 'requirements' => $this->getServerCompatibility(),
130: 'roles' => $wp_roles->roles,
131: 'caps' => $this->permissions->getAllCapabilitiesWithDescriptions(),
132: 'disableableStyles' => $this->getDisableableStyles(),
133: 'disableableScripts' => $this->getDisableableScripts()
134: ));
135: }
136:
137: 138: 139: 140: 141:
142: protected function getServerCompatibility()
143: {
144: $server = array(
145: 'phpVersion' => phpversion(),
146: 'mysqlVersion' => $this->repository->getDbVersion(),
147: 'wordpressVersion' => get_bloginfo('version'),
148: 'gdEnabled' => function_exists('imagecreate'),
149: 'ftEnabled' => function_exists('imagettftext'),
150: 'zipEnabled' => extension_loaded('zip'),
151: 'tmpDir' => Quform::getTempDir('quform'),
152: 'cacheDir' => $this->scriptLoader->getCachePath(),
153: 'uploadsDir' => Quform::getUploadsDir()
154: );
155:
156: $compatibility = array(
157: 'php' => array(
158: 'name' => __('PHP Version', 'quform'),
159: 'info' => $server['phpVersion']
160: ),
161: 'mysql' => array(
162: 'name' => __('MySQL Version', 'quform'),
163: 'info' => $server['mysqlVersion']
164: ),
165: 'wordpress' => array(
166: 'name' => __('WordPress Version', 'quform'),
167: 'info' => $server['wordpressVersion']
168: ),
169: 'gd' => array(
170: 'name' => __('GD Image Library', 'quform'),
171: 'info' => $server['gdEnabled'] ? __('Available', 'quform') : __('Unavailable', 'quform')
172: ),
173: 'ft' => array(
174: 'name' => __('FreeType Library', 'quform'),
175: 'info' => $server['ftEnabled'] ? __('Available', 'quform') : __('Unavailable', 'quform')
176: ),
177: 'zip' => array(
178: 'name' => __('Zip Extension', 'quform'),
179: 'info' => $server['zipEnabled'] ? __('Available', 'quform') : __('Unavailable', 'quform')
180: ),
181: 'tmp' => array(
182: 'name' => __('Temporary Directory', 'quform'),
183: 'info' => $server['tmpDir'],
184: ),
185: 'cache' => array(
186: 'name' => __('Cache Directory', 'quform'),
187: 'info' => $server['cacheDir'],
188: ),
189: 'uploads' => array(
190: 'name' => __('Uploads Directory', 'quform'),
191: 'info' => $server['uploadsDir'],
192: )
193: );
194:
195: if (version_compare($server['phpVersion'], '5.2', '<')) {
196: $compatibility['php']['error'] = __('The plugin requires PHP version 5.2 or later.', 'quform');
197: }
198:
199: if (version_compare($server['mysqlVersion'], '5.0.0', '<')) {
200: $compatibility['mysql']['error'] = __('The plugin requires MySQL version 5 or later.', 'quform');
201: }
202:
203: if (version_compare($server['wordpressVersion'], '4.5', '<')) {
204: $compatibility['wordpress']['error'] = __('The plugin requires WordPress version 4.5 or later.', 'quform');
205: }
206:
207: if ( ! $server['gdEnabled']) {
208: $compatibility['gd']['error'] = __('The plugin requires the GD image library for the CAPTCHA element.', 'quform');
209: }
210:
211: if ( ! $server['ftEnabled']) {
212: $compatibility['ft']['error'] = __('The plugin requires the FreeType library for the CAPTCHA element.', 'quform');
213: }
214:
215: if ( ! $server['zipEnabled']) {
216: $compatibility['zip']['error'] = __('The plugin requires the Zip PHP extension to export entries.', 'quform');
217: }
218:
219: if ( ! is_dir($server['tmpDir'])) {
220: $compatibility['tmp']['error'] = __('The temporary directory does not exist, please create the directory and make it writable.', 'quform');
221: } else if ( ! wp_is_writable($server['tmpDir'])) {
222: $compatibility['tmp']['error'] = __('The temporary directory is not writable.', 'quform');
223: }
224:
225: if ( ! is_dir($server['cacheDir'])) {
226: $compatibility['cache']['error'] = __('The plugin cache directory does not exist, please create the directory and make it writable.', 'quform');
227: } else if ( ! wp_is_writable($server['cacheDir'])) {
228: $compatibility['cache']['error'] = __('The plugin cache directory is not writable.', 'quform');
229: }
230:
231: if ( ! is_dir($server['uploadsDir'])) {
232: $compatibility['uploads']['error'] = __('The WordPress uploads directory does not exist, please create the directory and make it writable.', 'quform');
233: } else if ( ! wp_is_writable($server['uploadsDir'])) {
234: $compatibility['uploads']['error'] = __('The WordPress uploads directory is not writable.', 'quform');
235: }
236:
237: return $compatibility;
238: }
239:
240: 241: 242: 243: 244:
245: protected function getDisableableStyles()
246: {
247: return array(
248: 'font_awesome' => array(
249: 'disabled' => $this->options->get('disabledStyles.fontAwesome'),
250: 'name' => 'Font Awesome',
251: 'version' => 'v4.7.0',
252: 'tooltip' => __('Used for displaying icons in various parts of the form.', 'quform')
253: ),
254: 'select2' => array(
255: 'disabled' => $this->options->get('disabledStyles.select2'),
256: 'name' => 'Select2',
257: 'version' => 'v4.0.13',
258: 'tooltip' => __('Used as a select menu replacement.', 'quform')
259: ),
260: 'qtip' => array(
261: 'disabled' => $this->options->get('disabledStyles.qtip'),
262: 'name' => 'qTip',
263: 'version' => 'v3.0.3',
264: 'tooltip' => __('Used for displaying tooltips in the form.', 'quform')
265: ),
266: 'fancybox' => array(
267: 'disabled' => $this->options->get('disabledStyles.fancybox'),
268: 'name' => 'Fancybox',
269: 'version' => 'v1.3.9',
270: 'tooltip' => __('Used for displaying the form in a popup.', 'quform'),
271: 'hidden' => ! $this->options->get('popupEnabled') || $this->options->get('popupScript') != 'fancybox-1'
272: ),
273: 'fancybox2' => array(
274: 'disabled' => $this->options->get('disabledStyles.fancybox2'),
275: 'name' => 'Fancybox',
276: 'version' => 'v2.1.9',
277: 'tooltip' => __('Used for displaying the form in a popup.', 'quform'),
278: 'hidden' => ! $this->options->get('popupEnabled') || $this->options->get('popupScript') != 'fancybox-2'
279: ),
280: 'fancybox3' => array(
281: 'disabled' => $this->options->get('disabledStyles.fancybox3'),
282: 'name' => 'Fancybox',
283: 'version' => 'v3.5.7',
284: 'tooltip' => __('Used for displaying the form in a popup.', 'quform'),
285: 'hidden' => ! $this->options->get('popupEnabled') || $this->options->get('popupScript') != 'fancybox-3'
286: ),
287: 'magnific_popup' => array(
288: 'disabled' => $this->options->get('disabledStyles.magnificPopup'),
289: 'name' => 'Magnific Popup',
290: 'version' => 'v1.1.0',
291: 'tooltip' => __('Used for displaying the form in a popup.', 'quform'),
292: 'hidden' => ! $this->options->get('popupEnabled') || $this->options->get('popupScript') != 'magnific-popup'
293: )
294: );
295: }
296:
297: 298: 299: 300: 301:
302: protected function getDisableableScripts()
303: {
304: return array(
305: 'file_upload' => array(
306: 'disabled' => $this->options->get('disabledScripts.fileUpload'),
307: 'name' => 'jQuery File Upload',
308: 'version' => 'v9.21.0',
309: 'tooltip' => __('Used for adding upload progress to File Upload elements.', 'quform')
310: ),
311: 'scroll_to' => array(
312: 'disabled' => $this->options->get('disabledScripts.scrollTo'),
313: 'name' => 'jQuery.scrollTo',
314: 'version' => 'v2.1.2',
315: 'tooltip' => __('Used for animated scrolling to success and error messages.', 'quform')
316: ),
317: 'select2' => array(
318: 'disabled' => $this->options->get('disabledScripts.select2'),
319: 'name' => 'Select2',
320: 'version' => 'v4.0.13',
321: 'tooltip' => __('Used as a select menu replacement.', 'quform')
322: ),
323: 'qtip' => array(
324: 'disabled' => $this->options->get('disabledScripts.qtip'),
325: 'name' => 'qTip',
326: 'version' => 'v3.0.3',
327: 'tooltip' => __('Used for displaying tooltips in the form.', 'quform')
328: ),
329: 'fancybox' => array(
330: 'disabled' => $this->options->get('disabledScripts.fancybox'),
331: 'name' => 'Fancybox',
332: 'version' => 'v1.3.9',
333: 'tooltip' => __('Used for displaying the form in a popup.', 'quform'),
334: 'hidden' => ! $this->options->get('popupEnabled') || $this->options->get('popupScript') != 'fancybox-1'
335: ),
336: 'fancybox2' => array(
337: 'disabled' => $this->options->get('disabledScripts.fancybox2'),
338: 'name' => 'Fancybox',
339: 'version' => 'v2.1.9',
340: 'tooltip' => __('Used for displaying the form in a popup.', 'quform'),
341: 'hidden' => ! $this->options->get('popupEnabled') || $this->options->get('popupScript') != 'fancybox-2'
342: ),
343: 'fancybox3' => array(
344: 'disabled' => $this->options->get('disabledScripts.fancybox3'),
345: 'name' => 'Fancybox',
346: 'version' => 'v3.5.7',
347: 'tooltip' => __('Used for displaying the form in a popup.', 'quform'),
348: 'hidden' => ! $this->options->get('popupEnabled') || $this->options->get('popupScript') != 'fancybox-3'
349: ),
350: 'magnific_popup' => array(
351: 'disabled' => $this->options->get('disabledScripts.magnificPopup'),
352: 'name' => 'Magnific Popup',
353: 'version' => 'v1.1.0',
354: 'tooltip' => __('Used for displaying the form in a popup.', 'quform'),
355: 'hidden' => ! $this->options->get('popupEnabled') || $this->options->get('popupScript') != 'magnific-popup'
356: ),
357: 'infield_labels' => array(
358: 'disabled' => $this->options->get('disabledScripts.infieldLabels'),
359: 'name' => 'Infield Labels',
360: 'version' => 'v0.1.5',
361: 'tooltip' => __('Used for displaying labels inside fields.', 'quform')
362: ),
363: 'datepicker' => array(
364: 'disabled' => $this->options->get('disabledScripts.datepicker'),
365: 'name' => 'Datepicker',
366: 'version' => 'v2020.2.617',
367: 'tooltip' => __('Used for displaying a datepicker calendar on the Date element.', 'quform')
368: ),
369: 'timepicker' => array(
370: 'disabled' => $this->options->get('disabledScripts.timepicker'),
371: 'name' => 'Timepicker',
372: 'version' => 'v2020.2.617',
373: 'tooltip' => __('Used for displaying a timepicker list on the Time element.', 'quform')
374: )
375: );
376: }
377: }
378: