forked from marekmurawski/mm_thumbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstall.php
74 lines (63 loc) · 2.13 KB
/
uninstall.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/* Security measure */
if (!defined('IN_CMS')) {
exit();
}
error_reporting( -1 );
set_error_handler( array( 'Error', 'captureNormal' ) );
set_exception_handler( array( 'Error', 'captureException' ) );
register_shutdown_function( array( 'Error', 'captureShutdown' ) );
class Error
{
public static $errors = array();
public static function captureNormal( $number, $message, $file, $line )
{ self::$errors[] = '<tr><td>MESSAGE:</td><td>' . $message .'</td></tr>'; }
public static function captureException( $exception )
{
echo '<pre>' . print_r( $exception, true) . '</pre>';
self::$errors[] = print_r( $exception, true);
}
public static function captureShutdown( )
{
$error = error_get_last( );
if( $error || count(self::$errors)>0 ) {
self::$errors[] = '<tr><td>MESSAGE:</td><td>' . $error['message'] .'</td></tr>';
$message = __('Errors while uninstalling plugin:') .'<table>'. implode(PHP_EOL, self::$errors) . '</table>';
Flash::set('error',$message);
echo $message;
} else {
Flash::set('success',__('Uninstalled mmThumbs plugin'));
}
}
}
function recursive_remove_directory($directory, $empty = FALSE) {
if (substr($directory, -1) == '/') {
$directory = substr($directory, 0, -1);
}
if (!file_exists($directory) || !is_dir($directory)) {
return FALSE;
} elseif (is_readable($directory)) {
$handle = opendir($directory);
while (FALSE !== ($item = readdir($handle))) {
if ($item != '.' && $item != '..') {
$path = $directory . '/' . $item;
if (is_dir($path)) {
recursive_remove_directory($path);
} else {
unlink($path);
//Error::$errors[] = substr($path,strlen(CMS_ROOT)).'<br/>';
}
}
}
closedir($handle);
if ($empty == FALSE) {
if (!rmdir($directory)) {
return FALSE;
}
}
}
return TRUE;
}
$rmDir = CMS_ROOT . '/thmm';
recursive_remove_directory($rmDir);
exit();