| @@ -10,9 +10,9 @@ | ||
| 10 | 10 | class LP_WP_Filesystem { |
| 11 | 11 | /** |
| 12 | 12 | * @var WP_Filesystem_Direct |
| 13 | 13 | */ |
| 14 | - protected $lp_filesystem; | |
| 14 | + public $lp_filesystem; | |
| 15 | 15 | /** |
| 16 | 16 | * @var LP_WP_Filesystem |
| 17 | 17 | */ |
| 18 | 18 | protected static $instance; |
| @@ -40,9 +40,9 @@ | ||
| 40 | 40 | |
| 41 | 41 | return self::$instance; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - public static function wp_file_system() { | |
| 44 | + /*public static function wp_file_system() { | |
| 45 | 45 | global $wp_filesystem; |
| 46 | 46 | |
| 47 | 47 | if ( empty( $wp_filesystem ) ) { |
| 48 | 48 | require_once ABSPATH . '/wp-admin/includes/file.php'; |
| @@ -47,9 +47,9 @@ | ||
| 47 | 47 | if ( empty( $wp_filesystem ) ) { |
| 48 | 48 | require_once ABSPATH . '/wp-admin/includes/file.php'; |
| 49 | 49 | WP_Filesystem(); |
| 50 | 50 | } |
| 51 | - } | |
| 51 | + }*/ | |
| 52 | 52 | |
| 53 | 53 | public static function chmod_dir(): int { |
| 54 | 54 | if ( defined( 'FS_CHMOD_DIR' ) ) { |
| 55 | 55 | $chmod_dir = FS_CHMOD_DIR; |
| @@ -177,42 +177,51 @@ | ||
| 177 | 177 | return $output; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
| 181 | - * @editor tungnx | |
| 182 | - * @modify 4.1.3.1 comment - replace file_get_contents | |
| 181 | + * Get content of file | |
| 182 | + * | |
| 183 | + * @param $path | |
| 184 | + * | |
| 185 | + * @return false|string | |
| 183 | 186 | */ |
| 184 | - /*public static function get_contents( $path ) { | |
| 185 | - _deprecated_function( __FUNCTION__, '4.1.3.1', 'file_get_contents' ); | |
| 187 | + public function file_get_contents( $path ) { | |
| 186 | 188 | $output = @file_get_contents( $path ); |
| 187 | 189 | |
| 188 | 190 | if ( ! $output ) { |
| 189 | - global $wp_filesystem; | |
| 190 | - self::wp_file_system(); | |
| 191 | - | |
| 192 | - if ( self::file_exists( $path ) ) { | |
| 193 | - $output = $wp_filesystem->get_contents( $path ); | |
| 194 | - } | |
| 191 | + $output = $this->lp_filesystem->get_contents( $path ); | |
| 195 | 192 | } |
| 196 | 193 | |
| 197 | 194 | return $output; |
| 198 | - }*/ | |
| 195 | + } | |
| 199 | 196 | |
| 200 | 197 | /** |
| 201 | - * Get content of file | |
| 198 | + * Get LearnPress icon SVG content from local plugin files. | |
| 202 | 199 | * |
| 203 | - * @param $path | |
| 200 | + * @param string $icon | |
| 204 | 201 | * |
| 205 | - * @return false|string | |
| 202 | + * @return string | |
| 206 | 203 | */ |
| 207 | - public function file_get_contents( $path ) { | |
| 208 | - $output = @file_get_contents( $path ); | |
| 204 | + public static function get_icon_svg( string $icon ): string { | |
| 205 | + static $icons = []; | |
| 209 | 206 | |
| 210 | - if ( ! $output ) { | |
| 211 | - $output = $this->lp_filesystem->get_contents( $path ); | |
| 207 | + $icon = ltrim( $icon, '/' ); | |
| 208 | + if ( '' === $icon ) { | |
| 209 | + return ''; | |
| 212 | 210 | } |
| 213 | 211 | |
| 214 | - return $output; | |
| 212 | + if ( ! isset( $icons[ $icon ] ) ) { | |
| 213 | + $icons[ $icon ] = ''; | |
| 214 | + $svg_path = LP_PLUGIN_PATH . 'assets/images/icons/' . $icon; | |
| 215 | + $lp_filesystem = self::instance(); | |
| 216 | + | |
| 217 | + if ( $lp_filesystem->file_exists( $svg_path ) ) { | |
| 218 | + $svg_content = $lp_filesystem->file_get_contents( $svg_path ); | |
| 219 | + $icons[ $icon ] = is_string( $svg_content ) ? $svg_content : ''; | |
| 220 | + } | |
| 221 | + } | |
| 222 | + | |
| 223 | + return $icons[ $icon ]; | |
| 215 | 224 | } |
| 216 | 225 | |
| 217 | 226 | /** |
| 218 | 227 | * Put content to file |
| @@ -347,7 +356,38 @@ | ||
| 347 | 356 | $output = $this->lp_filesystem->move( $source_path, $des_path, $overwrite ); |
| 348 | 357 | } |
| 349 | 358 | |
| 350 | 359 | return $output; |
| 360 | + } | |
| 361 | + | |
| 362 | + /** | |
| 363 | + * Code custom for user Unigrant is using. | |
| 364 | + */ | |
| 365 | + public function download_url( $url, $timeout = 300, $signature_verification = false ) { | |
| 366 | + return download_url( $url, $timeout, $signature_verification ); | |
| 367 | + } | |
| 368 | + | |
| 369 | + public function lp_handle_upload( &$file, $overrides = false, $time = null ) { | |
| 370 | + return wp_handle_upload( $file, $overrides, $time ); | |
| 371 | + } | |
| 372 | + | |
| 373 | + /** | |
| 374 | + * Get size of file from url | |
| 375 | + * | |
| 376 | + * @param $url | |
| 377 | + * | |
| 378 | + * @return string | |
| 379 | + * @since 4.2.3 | |
| 380 | + * @version 1.0.1 | |
| 381 | + * @depreacted 4.2.7.8.5 | |
| 382 | + */ | |
| 383 | + public function get_file_size_from_url( $url ) { | |
| 384 | + $tmp_file = $this->download_url( $url ); | |
| 385 | + $size = ''; | |
| 386 | + if ( $tmp_file && ! is_wp_error( $tmp_file ) ) { | |
| 387 | + $size = ( filesize( $tmp_file ) / 1024 < 1024 ) ? round( filesize( $tmp_file ) / 1024, 2 ) . 'KB' : round( filesize( $tmp_file ) / 1024 / 1024, 2 ) . 'MB'; | |
| 388 | + } | |
| 389 | + | |
| 390 | + return $size; | |
| 351 | 391 | } |
| 352 | 392 | } |
| 353 | 393 | } |