| @@ -6,30 +6,36 @@ | ||
| 6 | 6 | |
| 7 | 7 | // Exit if accessed directly. |
| 8 | 8 | use WPCoder\Optimization\Obfuscator; |
| 9 | 9 | use WPCoder\Optimization\CSSMinifier; |
| 10 | -use WPCoder\WOW_Plugin; | |
| 10 | +use WPCoder\WPCoder; | |
| 11 | 11 | |
| 12 | 12 | class FolderManager { |
| 13 | 13 | |
| 14 | 14 | public static function create(): void { |
| 15 | 15 | $basedir = self::path_upload_dir(); |
| 16 | + $index_file = $basedir . 'index.php'; | |
| 16 | 17 | |
| 17 | 18 | if ( ! file_exists( $basedir ) ) { |
| 18 | 19 | wp_mkdir_p( $basedir ); |
| 19 | 20 | } |
| 21 | + | |
| 22 | + if ( is_dir( $basedir ) && ! file_exists( $index_file ) ) { | |
| 23 | + file_put_contents($index_file, '<?php // Silence is golden.'); | |
| 24 | + } | |
| 20 | 25 | } |
| 21 | 26 | |
| 27 | + | |
| 22 | 28 | public static function path_upload_dir(): string { |
| 23 | 29 | $upload = wp_upload_dir(); |
| 24 | 30 | |
| 25 | - return $upload['basedir'] . '/' . WOW_Plugin::FOLDER . '/'; | |
| 31 | + return $upload['basedir'] . '/' . WPCoder::FOLDER . '/'; | |
| 26 | 32 | } |
| 27 | 33 | |
| 28 | 34 | public static function path_upload_url(): string { |
| 29 | 35 | $upload = wp_upload_dir(); |
| 30 | 36 | |
| 31 | - return $upload['baseurl'] . '/' . WOW_Plugin::FOLDER . '/'; | |
| 37 | + return $upload['baseurl'] . '/' . WPCoder::FOLDER . '/'; | |
| 32 | 38 | } |
| 33 | 39 | |
| 34 | 40 | public static function get_style_url( $result ): string { |
| 35 | 41 | $path_style = self::path_upload_dir() . 'style-' . $result->id . '.css'; |
| @@ -96,8 +102,35 @@ | ||
| 96 | 102 | |
| 97 | 103 | return file_put_contents( $path_js, $js_code ); |
| 98 | 104 | } |
| 99 | 105 | |
| 106 | + public static function code_path( $result ): string { | |
| 107 | + | |
| 108 | + $path = self::path_upload_dir() . 'wp-code-' . $result->id . '.php'; | |
| 109 | + | |
| 110 | + if ( ! file_exists( $path ) ) { | |
| 111 | + $content = "<?php\n\n defined( 'ABSPATH' ) || exit;\n"; | |
| 112 | + $content .= $result->php_code; | |
| 113 | + file_put_contents( $path, $content ); | |
| 114 | + } | |
| 115 | + | |
| 116 | + return self::path_upload_dir() . 'wp-code-' . $result->id . '.php'; | |
| 117 | + } | |
| 118 | + | |
| 119 | + public static function update_code( $data, $id) { | |
| 120 | + | |
| 121 | + if ( ! is_numeric( $id ) ) { | |
| 122 | + return false; | |
| 123 | + } | |
| 124 | + | |
| 125 | + $path = self::path_upload_dir() . 'wp-code-' . $id . '.php'; | |
| 126 | + | |
| 127 | + $content = "<?php\n\n defined( 'ABSPATH' ) || exit;\n"; | |
| 128 | + $content .= $data['php_code']; | |
| 129 | + | |
| 130 | + return file_put_contents( $path, $content ); | |
| 131 | + } | |
| 132 | + | |
| 100 | 133 | public static function update_files( $data, $id ): void { |
| 101 | 134 | if ( ! empty( $data['css_code'] ) ) { |
| 102 | 135 | self::update_style( $data, $id ); |
| 103 | 136 | } |
| @@ -102,7 +135,11 @@ | ||
| 102 | 135 | self::update_style( $data, $id ); |
| 103 | 136 | } |
| 104 | 137 | if ( ! empty( $data['js_code'] ) ) { |
| 105 | 138 | self::update_script( $data, $id ); |
| 139 | + } | |
| 140 | + | |
| 141 | + if ( ! empty( $data['php_code'] ) ) { | |
| 142 | + self::update_code( $data, $id ); | |
| 106 | 143 | } |
| 107 | 144 | } |
| 108 | 145 | } |