| @@ -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; |
| @@ -194,8 +194,37 @@ | ||
| 194 | 194 | return $output; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
| 198 | + * Get LearnPress icon SVG content from local plugin files. | |
| 199 | + * | |
| 200 | + * @param string $icon | |
| 201 | + * | |
| 202 | + * @return string | |
| 203 | + */ | |
| 204 | + public static function get_icon_svg( string $icon ): string { | |
| 205 | + static $icons = []; | |
| 206 | + | |
| 207 | + $icon = ltrim( $icon, '/' ); | |
| 208 | + if ( '' === $icon ) { | |
| 209 | + return ''; | |
| 210 | + } | |
| 211 | + | |
| 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 ]; | |
| 224 | + } | |
| 225 | + | |
| 226 | + /** | |
| 198 | 227 | * Put content to file |
| 199 | 228 | * |
| 200 | 229 | * @param $path |
| 201 | 230 | * @param $content |
| @@ -327,7 +356,38 @@ | ||
| 327 | 356 | $output = $this->lp_filesystem->move( $source_path, $des_path, $overwrite ); |
| 328 | 357 | } |
| 329 | 358 | |
| 330 | 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; | |
| 331 | 391 | } |
| 332 | 392 | } |
| 333 | 393 | } |