| 1 |
<?php |
| 2 |
/** |
| 3 |
* This file is part of the wp-monalisa plugin for WordPress |
| 4 |
* |
| 5 |
* Copyright 2010 Hans Matzen (email : webmaster at tuxlog.de) |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
* (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 |
* |
| 21 |
* @package wp-forecast |
| 22 |
*/ |
| 23 |
|
| 24 |
/** |
| 25 |
* Backup the files changed by the user |
| 26 |
*/ |
| 27 |
function hm_backup_wpf() { |
| 28 |
global $wp_filesystem; |
| 29 |
|
| 30 |
// name for backup directory. |
| 31 |
$backupdir = $wp_filesystem->wp_content_dir() . '/upgrade/wpf_update/'; |
| 32 |
|
| 33 |
// wenn vorhanden, altes backup verzeichnis löschen. |
| 34 |
if ( is_dir( $backupdir ) ) { |
| 35 |
$wp_filesystem->delete( $backupdir, true ); |
| 36 |
} |
| 37 |
|
| 38 |
// backupdir anlegen. |
| 39 |
$wp_filesystem->mkdir( $backupdir ); |
| 40 |
|
| 41 |
// individuelle css datei sichern. |
| 42 |
if ( $wp_filesystem->is_file( dirname( __FILE__ ) . '/wp-forecast.css' ) ) { |
| 43 |
$wp_filesystem->copy( |
| 44 |
dirname( __FILE__ ) . '/wp-forecast.css', |
| 45 |
$backupdir . '/wp-forecast.css' |
| 46 |
); |
| 47 |
} |
| 48 |
|
| 49 |
// individuelle css datei sichern. |
| 50 |
if ( $wp_filesystem->is_file( dirname( __FILE__ ) . '/wp-forecast-nowp.css' ) ) { |
| 51 |
$wp_filesystem->copy( |
| 52 |
dirname( __FILE__ ) . '/wp-forecast-nowp.css', |
| 53 |
$backupdir . '/wp-forecast-nowp.css' |
| 54 |
); |
| 55 |
} |
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Restoer files changed by the user |
| 61 |
*/ |
| 62 |
function hm_recover_wpf() { |
| 63 |
global $wp_filesystem; |
| 64 |
|
| 65 |
$backupdir = $wp_filesystem->wp_content_dir() . '/upgrade/wpf_update/'; |
| 66 |
$pdir = dirname( __FILE__ ); |
| 67 |
|
| 68 |
// individuelle css datei zurück holen. |
| 69 |
if ( $wp_filesystem->is_file( $backupdir . '/wp-forecast.css' ) ) { |
| 70 |
$wp_filesystem->copy( |
| 71 |
$backupdir . '/wp-forecast.css', |
| 72 |
$pdir . '/wp-forecast.css' |
| 73 |
); |
| 74 |
} |
| 75 |
|
| 76 |
// individuelle css datei zurück holen. |
| 77 |
if ( $wp_filesystem->is_file( $backupdir . '/wp-forecast-nowp.css' ) ) { |
| 78 |
$wp_filesystem->copy( |
| 79 |
$backupdir . '/wp-forecast-nowp.css', |
| 80 |
$pdir . '/wp-forecast-nowp.css' |
| 81 |
); |
| 82 |
} |
| 83 |
|
| 84 |
// backup verzeichnis löschen. |
| 85 |
$wp_filesystem->delete( $backupdir, true ); |
| 86 |
} |
| 87 |
|
| 88 |
// add filter. |
| 89 |
add_filter( 'upgrader_pre_install', 'hm_backup_wpf', 10, 2 ); |
| 90 |
add_filter( 'upgrader_post_install', 'hm_recover_wpf', 10, 2 ); |
| 91 |
|
| 92 |
|
| 93 |
|