010009.php
7 months ago
010300.php
7 months ago
010306.php
7 months ago
010309.php
7 months ago
010402.php
7 months ago
010501.php
3 months ago
010802.php
7 months ago
010803.php
3 months ago
index.php
3 years ago
010501.php
84 lines
| 1 | <?php |
| 2 | |
| 3 | // Exit if accessed directly |
| 4 | if ( ! defined( 'ABSPATH' ) ) { |
| 5 | exit; |
| 6 | } |
| 7 | |
| 8 | /** |
| 9 | * Updates for altering the table used to store statistics data. |
| 10 | * Adds new columns and renames existing ones in order to add support for the new social buttons. |
| 11 | */ |
| 12 | class WIOUpdate010501 extends Wbcr_Factory600_Update { |
| 13 | |
| 14 | /** |
| 15 | * {inherit} |
| 16 | * |
| 17 | * @since 1.3.9 |
| 18 | */ |
| 19 | public function install() { |
| 20 | $old_dir = $this->get_old_dir(); |
| 21 | $new_dir = WRIO_Plugin::app()->logger->get_base_dir(); |
| 22 | |
| 23 | $files = array_diff( scandir( $old_dir ), [ '..', '.' ] ); |
| 24 | foreach ( $files as $file ) { |
| 25 | @copy( $old_dir . $file, $new_dir . $file ); |
| 26 | } |
| 27 | WRIO_Plugin::app()->logger->info( 'Plugin migration to 1.5.1 was successful!' ); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Get base directory, location of logs. |
| 32 | * |
| 33 | * @return null|string NULL in case of failure, string on success. |
| 34 | */ |
| 35 | public function get_old_dir() { |
| 36 | $wp_upload_dir = wp_upload_dir(); |
| 37 | |
| 38 | if ( isset( $wp_upload_dir['error'] ) && $wp_upload_dir['error'] !== false ) { |
| 39 | return null; |
| 40 | } |
| 41 | |
| 42 | $base_path = wp_normalize_path( trailingslashit( $wp_upload_dir['basedir'] ) . 'wrio/' ); |
| 43 | |
| 44 | $folders = glob( $base_path . 'logs-*' ); |
| 45 | |
| 46 | if ( ! empty( $folders ) ) { |
| 47 | $exploded_path = explode( '/', trim( $folders[0] ) ); |
| 48 | $selected_logs_folder = array_pop( $exploded_path ); |
| 49 | } else { |
| 50 | if ( function_exists( 'wp_salt' ) ) { |
| 51 | $hash = md5( wp_salt() ); |
| 52 | } else { |
| 53 | $hash = md5( AUTH_KEY ); |
| 54 | } |
| 55 | |
| 56 | $selected_logs_folder = 'logs-' . $hash; |
| 57 | } |
| 58 | |
| 59 | $path = $base_path . $selected_logs_folder . '/'; |
| 60 | |
| 61 | if ( ! file_exists( $path ) ) { |
| 62 | @mkdir( $path, 0755, true ); |
| 63 | } |
| 64 | |
| 65 | // Create .htaccess file to protect log files |
| 66 | $htaccess_path = $path . '.htaccess'; |
| 67 | |
| 68 | if ( ! file_exists( $htaccess_path ) ) { |
| 69 | $htaccess_content = 'deny from all'; |
| 70 | @file_put_contents( $htaccess_path, $htaccess_content ); |
| 71 | } |
| 72 | |
| 73 | // Create index.htm file in case .htaccess is not support as a fallback |
| 74 | $index_path = $path . 'index.html'; |
| 75 | |
| 76 | if ( ! file_exists( $index_path ) ) { |
| 77 | @file_put_contents( $index_path, '' ); |
| 78 | } |
| 79 | |
| 80 | return $path; |
| 81 | } |
| 82 | |
| 83 | } |
| 84 |