文件操作 - Manager.php
返回文件管理
返回主菜单
删除本文件
文件: /home/www/public/wp-content/plugins/ionos-journey/inc/Manager.php
编辑文件内容
<?php namespace Ionos\Journey; use Michelf\Markdown; // Do not allow direct access! if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Manager class */ class Manager { /** * The current version of the core script. * * @var string */ const CORE_SCRIPT_VERSION = '1.0.0'; /** * The current version of the start script. * * @var string */ const START_SCRIPT_VERSION = '1.0.0'; /** * Manager constructor. */ public function __construct() { \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_style' ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( isset( $_GET['journey_persistance'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $this->persist_progress( $_GET['journey_persistance'] ); return; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( isset( $_GET['wp_tour'] ) ) { \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_core_script' ] ); } else { \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_start_script' ] ); } \add_filter( 'script_loader_tag', [ $this, 'add_type_attribute' ], 10, 3 ); } /** * Enqueue the core script. */ public function enqueue_core_script() { if ( Profile::is_enabled( \get_current_user_id(), 'journey_show' ) ) { global $current_screen; global $_wp_admin_css_colors; if ( Profile::is_enabled( \get_current_user_id(), 'journey_show' ) ) { \wp_enqueue_script( 'ionos-journey', \plugins_url( 'js/journey.js', __DIR__ ), null, self::CORE_SCRIPT_VERSION, true ); $config_array = Helper::get_configuration( 'journey' ); $theme_array = wp_json_encode( $_wp_admin_css_colors[ \get_user_option( 'admin_color', \get_current_user_id() ) ] ); $translation_array = Helper::get_configuration( 'interface' ); $page_config = wp_json_encode( $this->replace_markdown( $config_array[ $current_screen->id ] ), JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT ); $page_config = str_replace( '\\\\\\', '\\', $page_config ); \wp_localize_script( 'ionos-journey', 'IONOS', [ 'wp' => [ 'journey' => [ 'config' => $page_config, 'color' => $theme_array, 'language' => wp_json_encode( $translation_array ), 'progress' => \get_user_meta( \get_current_user_id(), 'journey_progress', true ), 'id' => \get_current_user_id(), ], ], ] ); } } } /** * Chane script tag type to module. * * @param string $tag current tag. * @param string $handle script handle. * @param string $src script src. * * @return string */ public function add_type_attribute( $tag, $handle, $src ) { if ( 'ionos-journey' === $handle || 'ionos-journey-menu' === $handle ) { $tag = '<script id="' . $handle . '-js" type="module" src="' . esc_url( $src ) . '"></script>'; } return $tag; } /** * Load internal resources */ public function enqueue_style() { \wp_enqueue_style( 'ionos-journey', Helper::get_css_url( 'ionos-journey.css' ), [], filemtime( Helper::get_css_path( 'ionos-journey.css' ) ) ); } /** * Enqueue the start script. */ public function enqueue_start_script() { if ( Profile::is_enabled( \get_current_user_id(), 'journey_show' ) ) { global $current_screen; $config_array = Helper::get_configuration( 'journey' ); $translations = Helper::get_configuration( 'interface' ); if ( isset( $config_array[ $current_screen->id ] ) && ! empty( $config_array[ $current_screen->id ] ) ) { \wp_enqueue_script( 'ionos-journey-menu', \plugins_url( 'js/add_start.js', __DIR__ ), null, self::START_SCRIPT_VERSION, true ); \wp_localize_script( 'ionos-journey-menu', 'IONOS', [ 'wp' => [ 'journey' => [ 'label' => $translations['name'], ], ], ] ); } } } /** * Persist the progress. * * @param string $method save or clear (default: save). */ private function persist_progress( $method = 'save' ) { if ( $method === 'save' ) { $post_body = file_get_contents( 'php://input' ); \update_user_meta( \get_current_user_id(), 'journey_progress', $post_body ); } elseif ( $method === 'clear' ) { \delete_user_meta( \get_current_user_id(), 'journey_progress' ); } } /** * Replace markdown in the config. * * @param array $json config. * * @return array */ private function replace_markdown( $json ) { $result = []; foreach ( $json as $key => $value ) { if ( is_array( $value ) ) { $result[] = $this->replace_element( $value ); } elseif ( $key === 'htmlContent' ) { $result[] = str_replace( "\n", '', Markdown::defaultTransform( $value ) ); } else { $result[] = $value; } } return $result; } /** * Replace markdown in the config element. * * @param array $element config. * * @return array */ private function replace_element( $element ) { $result = $element; foreach ( $element as $key => $value ) { if ( is_array( $value ) ) { $result[ $key ] = $this->replace_element( $value ); } elseif ( $key === 'htmlContent' ) { $result[ $key ] = str_replace( "\n", '', Markdown::defaultTransform( $value ) ); } } return $result; } }
修改文件时间
将文件时间修改为当前时间的前一年
删除文件