Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/tutor/classes/Tools_V2.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 + /**
3 + * Options for TutorLMS
4 + *
5 + * @package Tutor\Tools
6 + * @author Themeum <support@themeum.com>
7 + * @link https://themeum.com
8 + * @since 2.0.0
9 + */
10 +
11 + namespace Tutor;
12 +
13 + use TUTOR\Admin;
14 +
15 + if ( ! defined( 'ABSPATH' ) ) {
16 + exit;
17 + }
18 +
19 + /**
20 + * Tools class
21 + *
22 + * @since 2.0.0
23 + */
24 + class Tools_V2 {
25 +
26 + /**
27 + * Environment status
28 + *
29 + * @since 2.0.0
30 + *
31 + * @var string
32 + */
33 + private $environment_status;
34 +
35 + /**
36 + * Tools filed
37 + *
38 + * @since 2.0.0
39 + *
40 + * @var mixed
41 + */
42 + private $tools_fields;
43 +
44 + /**
45 + * Apply settings
46 + *
47 + * @since 2.0.0
48 + *
49 + * @return void send wp_json response
50 + */
51 + public function tutor_apply_settings() {
52 + $tutor_settings_log = get_option( 'tutor_settings_log' );
53 + $apply_id = $this->get_request_data( 'apply_id' );
54 +
55 + update_option( 'tutor_option', $tutor_settings_log[ $apply_id ]['dataset'] );
56 +
57 + wp_send_json_success( $tutor_settings_log[ $apply_id ] );
58 + }
59 +
60 + /**
61 + * Get request data
62 + *
63 + * @since 2.0.0
64 + *
65 + * @param mixed $var var.
66 + *
67 + * @return mixed
68 + */
69 + public function get_request_data( $var ) {
70 + return Input::sanitize_request_data( $var, null );
71 + }
72 +
73 + /**
74 + * Tools page
75 + *
76 + * @since 2.0.0
77 + *
78 + * @return void including template
79 + */
80 + public function load_tools_page() {
81 + $tools_fields = $this->get_tools_fields();
82 + $active_tab = Input::get( 'sub_page', 'status' );
83 + include tutor()->path . '/views/options/tools.php';
84 + }
85 +
86 + /**
87 + * Function options_tools
88 + *
89 + * @since 2.0.0
90 + *
91 + * @return array
92 + */
93 + private function get_tools_fields() {
94 + global $wpdb;
95 +
96 + if ( $this->tools_fields ) {
97 + // Return fields if already prepared.
98 + return $this->tools_fields;
99 + }
100 +
101 + $attr_tools = array(
102 + 'status' => array(
103 + 'label' => __( 'Status', 'tutor' ),
104 + 'slug' => 'status',
105 + 'desc' => __( 'Status Settings', 'tutor' ),
106 + 'template' => 'status',
107 + 'view_path' => tutor()->path . 'views/options/template/',
108 + 'icon' => 'tutor-icon-chart-pie',
109 + 'blocks' => array(
110 + 'wordpress_environment' => array(
111 + 'label' => __( 'WordPress environment', 'tutor' ),
112 + 'slug' => 'wordpress_environment',
113 + 'classes' => 'wordpress_environment',
114 + 'block_type' => 'column',
115 + 'fieldset' => array(
116 + array(
117 + array(
118 + 'key' => 'home_url',
119 + 'type' => 'info_row',
120 + 'label' => __( 'Home URL', 'tutor' ),
121 + 'status' => 'default',
122 + 'default' => $this->status( 'home_url' ),
123 + ),
124 + ),
125 + array(
126 + array(
127 + 'key' => 'wordpress_version',
128 + 'type' => 'info_col',
129 + 'label' => __( 'WordPress version', 'tutor' ),
130 + 'status' => 'default',
131 + 'default' => $this->status( 'wordpress_version' ),
132 +
133 + ),
134 + array(
135 + 'key' => 'wordpress_multisite',
136 + 'type' => 'info_col',
137 + 'label' => __( 'WordPress multisite', 'tutor' ),
138 + 'status' => 'default',
139 + 'default' => $this->status( 'wordpress_multisite' ),
140 +
141 + ),
142 + array(
143 + 'key' => 'wordpress_debug_mode',
144 + 'type' => 'info_col',
145 + 'label' => __( 'WordPress debug mode', 'tutor' ),
146 + 'status' => ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ) ? 'success' : 'default',
147 + 'default' => $this->status( 'wordpress_debug_mode' ),
148 +
149 + ),
150 + array(
151 + 'key' => 'language',
152 + 'type' => 'info_col',
153 + 'label' => __( 'Language', 'tutor' ),
154 + 'status' => 'default',
155 + 'default' => $this->status( 'language' ),
156 +
157 + ),
158 + ),
159 + array(
160 + array(
161 + 'key' => 'site_url',
162 + 'type' => 'info_row',
163 + 'label' => __( 'Site URL', 'tutor' ),
164 + 'status' => 'default',
165 + 'default' => $this->status( 'site_url' ),
166 +
167 + ),
168 + ),
169 + array(
170 + array(
171 + 'key' => 'tutor_version',
172 + 'type' => 'info_col',
173 + 'label' => __( 'Tutor version', 'tutor' ),
174 + 'status' => 'success',
175 + 'default' => $this->status( 'tutor_version' ),
176 +
177 + ),
178 + array(
179 + 'key' => 'wordpress_memory_limit',
180 + 'type' => 'info_col',
181 + 'label' => __( 'WordPress memory limit', 'tutor' ),
182 + 'status' => 'success',
183 + 'default' => $this->status( 'wordpress_memory_limit' ),
184 +
185 + ),
186 + array(
187 + 'key' => 'wordpress_cron',
188 + 'type' => 'info_col',
189 + 'label' => __( 'WordPress Cron', 'tutor' ),
190 + 'status' => ! empty( _get_cron_array() ) ? 'success' : 'default',
191 + 'default' => $this->status( 'wordpress_cron' ),
192 +
193 + ),
194 + array(
195 + 'key' => 'external_object_cache',
196 + 'type' => 'info_col',
197 + 'label' => __( 'External object cache', 'tutor' ),
198 + 'status' => 'default',
199 + 'default' => $this->status( 'external_object_cache' ),
200 +
201 + ),
202 + ),
203 + ),
204 + ),
205 + 'server_environment' => array(
206 + 'label' => __( 'Server environment', 'tutor' ),
207 + 'slug' => 'server_environment',
208 + 'block_type' => 'column',
209 + 'fieldset' => array(
210 + array(
211 + array(
212 + 'key' => 'server_info',
213 + 'type' => 'info_col',
214 + 'label' => __( 'Server info', 'tutor' ),
215 + 'status' => 'default',
216 + 'default' => $this->status( 'server_info' ),
217 +
218 + ),
219 + array(
220 + 'key' => 'php_version',
221 + 'type' => 'info_col',
222 + 'label' => __( 'PHP version', 'tutor' ),
223 + 'status' => 'default',
224 + 'default' => $this->status( 'php_version' ),
225 +
226 + ),
227 + array(
228 + 'key' => 'php_post_max_size',
229 + 'type' => 'info_col',
230 + 'label' => __( 'PHP post max size', 'tutor' ),
231 + 'status' => 'default',
232 + 'default' => $this->status( 'php_post_max_size' ),
233 +
234 + ),
235 + array(
236 + 'key' => 'php_time_limit',
237 + 'type' => 'info_col',
238 + 'label' => __( 'PHP time limit', 'tutor' ),
239 + 'status' => 'default',
240 + 'default' => $this->status( 'php_time_limit' ),
241 +
242 + ),
243 + array(
244 + 'key' => 'curl_version',
245 + 'type' => 'info_col',
246 + 'label' => __( 'cURL version', 'tutor' ),
247 + 'status' => 'default',
248 + 'default' => $this->status( 'curl_version' ),
249 +
250 + ),
251 + array(
252 + 'key' => 'language',
253 + 'type' => 'info_col',
254 + 'label' => __( 'Language', 'tutor' ),
255 + 'status' => 'default',
256 + 'default' => $this->status( 'language' ),
257 +
258 + ),
259 + ),
260 + array(
261 + array(
262 + 'key' => 'tutor_version',
263 + 'type' => 'info_col',
264 + 'label' => __( 'MySQL version', 'tutor' ),
265 + 'status' => 'default',
266 + 'default' => sprintf( 'Server: %s, Client: %s', $wpdb->dbh->server_info, $wpdb->dbh->client_info ),
267 + ),
268 + array(
269 + 'key' => 'wordpress_memory_limit',
270 + 'type' => 'info_col',
271 + 'label' => __( 'Default timezone is UTC', 'tutor' ),
272 + 'status' => 'default',
273 + 'default' => $this->status( 'default_timezone_is_utc' ),
274 + ),
275 + array(
276 + 'key' => 'wordpress_cron',
277 + 'type' => 'info_col',
278 + 'label' => __( 'fsockopen/cURL', 'tutor' ),
279 + 'status' => 'default',
280 + 'default' => $this->status( 'fsockopen_curl' ),
281 + ),
282 + array(
283 + 'key' => 'external_object_cache',
284 + 'type' => 'info_col',
285 + 'label' => __( 'DOMDocument', 'tutor' ),
286 + 'status' => 'default',
287 + 'default' => $this->status( 'dom_document' ),
288 + ),
289 + array(
290 + 'key' => 'external_object_cache',
291 + 'type' => 'info_col',
292 + 'label' => __( 'GZip', 'tutor' ),
293 + 'status' => 'default',
294 + 'default' => $this->status( 'gzip' ),
295 + ),
296 + array(
297 + 'key' => 'external_object_cache',
298 + 'type' => 'info_col',
299 + 'label' => __( 'Multibyte string', 'tutor' ),
300 + 'status' => 'default',
301 + 'default' => $this->status( 'multibyte_string' ),
302 + ),
303 + ),
304 + ),
305 + ),
306 + ),
307 + ),
308 + 'import_export' => array(
309 + 'label' => __( 'Import/Export', 'tutor' ),
310 + 'slug' => 'import_export',
311 + 'desc' => __( 'Import/Export Settings', 'tutor' ),
312 + 'template' => 'import_export',
313 + 'view_path' => tutor()->path . 'views/options/template/',
314 + 'icon' => 'tutor-icon-import-export',
315 + 'blocks' => array(),
316 + ),
317 + 'tutor_pages' => array(
318 + 'label' => __( 'Tutor Pages', 'tutor' ),
319 + 'slug' => 'tutor_pages',
320 +
321 + 'desc' => __( 'Tutor Pages Settings', 'tutor' ),
322 + 'template' => 'tutor_pages',
323 + 'view_path' => tutor()->path . 'views/options/template/',
324 + 'icon' => 'tutor-icon-page-review',
325 + 'blocks' => array(
326 + 'block' => array(),
327 + ),
328 + ),
329 + 'tutor_rest_api' => array(
330 + 'label' => __( 'Rest API', 'tutor' ),
331 + 'slug' => 'tutor_rest_api',
332 + 'desc' => __( 'Token List', 'tutor' ),
333 + 'template' => 'manage-tokens',
334 + 'view_path' => tutor()->path . 'views/pages/tools/',
335 + 'icon' => 'tutor-icon-api',
336 + 'blocks' => array(
337 + 'block' => array(),
338 + ),
339 + ),
340 + 'settings_log' => array(
341 + 'label' => __( 'Settings Log', 'tutor' ),
342 + 'slug' => 'settings_log',
343 + 'desc' => __( 'Settings Log', 'tutor' ),
344 + 'template' => 'settings-log',
345 + 'view_path' => tutor()->path . 'views/pages/tools/',
346 + 'icon' => 'tutor-icon-settings-log',
347 + 'blocks' => array(
348 + 'block' => array(),
349 + ),
350 + ),
351 + );
352 +
353 + $attr_tools = apply_filters( 'tutor/tools/extend/attr', apply_filters( 'tutor/tools/attr', apply_filters( 'tutor_tool_pages', $attr_tools ) ) );
354 +
355 + $this->tools_fields = $attr_tools;
356 +
357 + return $this->tools_fields;
358 + }
359 +
360 + /**
361 + * Get environment info
362 + *
363 + * @since 2.0.0
364 + *
365 + * @return array
366 + */
367 + private function get_environment_info() {
368 +
369 + if ( $this->environment_status ) {
370 + // Use runtime cache for repetitive call.
371 + return $this->environment_status;
372 + }
373 +
374 + // Figure out cURL version, if installed.
375 + $curl_version = '';
376 + if ( function_exists( 'curl_version' ) ) {
377 + $curl_version = curl_version();
378 + $curl_version = $curl_version['version'] . ', ' . $curl_version['ssl_version'];
379 + }
380 +
381 + // WP memory limit.
382 + $wp_memory_limit = tutor_utils()->let_to_num( WP_MEMORY_LIMIT );
383 + if ( function_exists( 'memory_get_usage' ) ) {
384 + $wp_memory_limit = max( $wp_memory_limit, tutor_utils()->let_to_num( @ini_get( 'memory_limit' ) ) );
385 + }
386 +
387 + $database_version = tutor_utils()->get_db_version();
388 +
389 + $this->environment_status = array(
390 + 'home_url' => get_option( 'home' ),
391 + 'site_url' => get_option( 'siteurl' ),
392 + 'version' => TUTOR_VERSION,
393 + 'wp_version' => get_bloginfo( 'version' ),
394 + 'wp_multisite' => is_multisite(),
395 + 'wp_memory_limit' => $wp_memory_limit,
396 + 'wp_debug_mode' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ),
397 + 'wp_cron' => ! ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ),
398 + 'language' => get_locale(),
399 + 'external_object_cache' => wp_using_ext_object_cache(),
400 + 'server_info' => isset( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : '',
401 + 'php_version' => phpversion(),
402 + 'php_post_max_size' => tutor_utils()->let_to_num( ini_get( 'post_max_size' ) ),
403 + 'php_max_execution_time' => ini_get( 'max_execution_time' ),
404 + 'php_max_input_vars' => ini_get( 'max_input_vars' ),
405 + 'curl_version' => $curl_version,
406 + 'suhosin_installed' => extension_loaded( 'suhosin' ),
407 + 'max_upload_size' => wp_max_upload_size(),
408 + 'mysql_version' => $database_version['number'],
409 + 'mysql_version_string' => $database_version['string'],
410 + 'default_timezone' => date_default_timezone_get(),
411 + 'fsockopen_or_curl_enabled' => ( function_exists( 'fsockopen' ) || function_exists( 'curl_init' ) ),
412 + 'soapclient_enabled' => class_exists( 'SoapClient' ),
413 + 'domdocument_enabled' => class_exists( 'DOMDocument' ),
414 + 'gzip_enabled' => is_callable( 'gzopen' ),
415 + 'mbstring_enabled' => extension_loaded( 'mbstring' ),
416 + );
417 +
418 + return $this->environment_status;
419 + }
420 +
421 + /**
422 + * Status
423 + *
424 + * @since 2.0.0
425 + *
426 + * @param string $type type.
427 + *
428 + * @return mixed
429 + */
430 + public function status( $type = '' ) {
431 +
432 + $data = array();
433 + $data[ null ] = 'null';
434 +
435 + $environment = $this->get_environment_info();
436 +
437 + $data['home_url'] = $environment['home_url'] ?? null;
438 + $data['site_url'] = $environment['site_url'] ?? null;
439 +
440 + $latest_version = get_transient( 'tutor_system_status_wp_version_check' );
441 +
442 + // WordPress already has efficient update notification mechanism.
443 + // We don't need to slow down the page for no reason.
444 + // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment
445 + $data['wordpress_version'] = esc_html( $environment['wp_version'] );
446 +
447 + $data['tutor_version'] = esc_html( $environment['version'] );
448 +
449 + $data['wordpress_multisite'] = $environment['wp_multisite'] ? '✓' : '-';
450 +
451 + $data['wordpress_debug_mode'] = $environment['wp_debug_mode'] ? '✓' : '-';
452 +
453 + $data['language'] = esc_html( $environment['language'] );
454 +
455 + $data['wordpress_memory_limit'] = ( $environment['wp_memory_limit'] < 67108864 )
456 + ? sprintf( esc_html__( '%1$s - We recommend setting memory to at least 64MB. See: %2$s', 'tutor' ), esc_html( size_format( $environment['wp_memory_limit'] ) ), '<a href="https://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP" target="_blank">' . esc_html__( 'Increasing memory allocated to PHP', 'tutor' ) . '</a>' )
457 + : esc_html( size_format( $environment['wp_memory_limit'] ) );
458 +
459 + $data['wordpress_cron'] = $environment['wp_cron'] ? '✓' : '-';
460 +
461 + $data['external_object_cache'] = $environment['external_object_cache'] ? '✓' : '-';
462 +
463 + $data['server_info'] = $environment['server_info'] ?? null;
464 +
465 + $data['php_version'] = ( version_compare( $environment['php_version'], '7.2', '>=' ) )
466 + ? esc_html( $environment['php_version'] )
467 + : ( ( version_compare( $environment['php_version'], '5.6', '<' ) )
468 + ? __( 'Tutor will run under this version of PHP, however, it has reached end of life. We recommend using PHP version 7.2 or above for greater performance and security.', 'tutor' )
469 + : __( 'We recommend using PHP version 7.2 or above for greater performance and security.', 'tutor' ) );
470 +
471 + $data['php_post_max_size'] = esc_html( size_format( $environment['php_post_max_size'] ) ) ?? null;
472 +
473 + $data['php_time_limit'] = esc_html( $environment['php_max_execution_time'] ) ?? null;
474 +
475 + $data['php_max_input_vars'] = esc_html( $environment['php_max_input_vars'] ) ?? null;
476 +
477 + $data['curl_version'] = esc_html( $environment['curl_version'] ) ?? null;
478 +
479 + $data['suhosin_installed'] = $environment['suhosin_installed'] ? '✓' : '-';
480 +
481 + $data['max_upload_size'] = esc_html( size_format( $environment['max_upload_size'] ) ) ?? null;
482 +
483 + $data['mysql_version'] = ( version_compare( $environment['mysql_version'], '5.6', '<' ) && ! strstr( $environment['mysql_version_string'], 'MariaDB' ) )
484 + ?
485 + /* translators: %1$s: MySQL version number, %2$s: WordPress requirements URL */
486 + sprintf( esc_html__( '%1$s - We recommend a minimum MySQL version of 5.6. See: %2$s', 'tutor' ), esc_html( $environment['mysql_version_string'] ), '<a href="https://wordpress.org/about/requirements/" target="_blank">' . esc_html__( 'WordPress requirements', 'tutor' ) . '</a>' )
487 + : esc_html( $environment['mysql_version_string'] );
488 +
489 + $data['default_timezone_is_utc'] = ( 'UTC' !== $environment['default_timezone'] )
490 + ?
491 + /* translators: %s: default timezone */
492 + sprintf( esc_html__( 'Default timezone is %s - it should be UTC', 'tutor' ), esc_html( $environment['default_timezone'] ) )
493 + : '✓';
494 +
495 + $data['fsockopen_curl'] = $environment['fsockopen_or_curl_enabled']
496 + ? '✓'
497 + : esc_html__( 'Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', 'tutor' );
498 +
499 + $data['dom_document'] = $environment['domdocument_enabled']
500 + ? '✓'
501 + :
502 + /* translators: %s: classname and link. */
503 + sprintf( esc_html__( 'Your server does not have the %s class enabled - HTML/Multipart emails, and also some extensions, will not work without DOMDocument.', 'tutor' ), '<a href="https://php.net/manual/en/class.domdocument.php">DOMDocument</a>' );
504 +
505 + $data['gzip'] = ( $environment['gzip_enabled'] )
506 + ? '✓'
507 + :
508 + /* translators: %s: classname and link. */
509 + sprintf( esc_html__( 'Your server does not support the %s function - this is required to use the GeoIP database from MaxMind.', 'tutor' ), '<a href="https://php.net/manual/en/zlib.installation.php">gzopen</a>' );
510 +
511 + $data['multibyte_string'] = ( $environment['mbstring_enabled'] )
512 + ? '✓'
513 + :
514 + /* translators: %s: classname and link. */
515 + sprintf( esc_html__( 'Your server does not support the %s functions - this is required for better character encoding. Some fallbacks will be used instead for it.', 'tutor' ), '<a href="https://php.net/manual/en/mbstring.installation.php">mbstring</a>' );
516 +
517 + if ( ! null == $type ) {
518 + return $data[ $type ];
519 + }
520 +
521 + return $data[ null ];
522 + }
523 +
524 + /**
525 + * Generate Option Field
526 + *
527 + * @since 2.0.0
528 + *
529 + * @param array $field fields.
530 + *
531 + * @return string
532 + */
533 + public function generate_field( $field = array() ) {
534 + ob_start();
535 + include tutor()->path . "views/options/field-types/{$field['type']}.php";
536 +
537 + return ob_get_clean();
538 + }
539 +
540 + /**
541 + * Get field type template
542 + *
543 + * @since 2.0.0
544 + *
545 + * @param array $field field.
546 + *
547 + * @return string
548 + */
549 + public function field_type( $field = array() ) {
550 + ob_start();
551 + include tutor()->path . "views/options/field-types/{$field['type']}.php";
552 + return ob_get_clean();
553 + }
554 +
555 + /**
556 + * Blocks template content
557 + *
558 + * @since 2.0.0
559 + *
560 + * @param array $blocks field.
561 + *
562 + * @return string
563 + */
564 + public function blocks( $blocks = array() ) {
565 + ob_start();
566 + include tutor()->path . 'views/options/option_blocks.php';
567 + return ob_get_clean();
568 + }
569 +
570 + /**
571 + * Template content
572 + *
573 + * @since 2.0.0
574 + *
575 + * @param array $section field.
576 + *
577 + * @return string
578 + */
579 + public function template( $section = array() ) {
580 + ob_start();
581 + include $section['view_path'] . $section['template'] . '.php';
582 + return ob_get_clean();
583 + }
584 +
585 + /**
586 + * Load template inside template directory
587 + *
588 + * @since 2.0.0
589 + *
590 + * @param string $template_slug template slug.
591 + * @param array $section sections array.
592 + *
593 + * @return string
594 + */
595 + public function view_template( $template_slug, $section = array() ) {
596 + ob_start();
597 + require tutor()->path . "views/options/template/{$template_slug}";
598 + return ob_get_clean();
599 + }
600 + }
601 +