/var/www/(Del)hsihk.com/wp-content/plugins/backupbuddy/controllers/pages/server_info/database.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
if ( !isset( $parent_class ) ) {
    
$parent_class $this;
}
if ( 
defined'pluginbuddy_importbuddy' ) ) {
    
//$parent_class->admin_scripts();
}





$profile_id 0;
if ( 
is_numericpb_backupbuddy::_GET'profile' ) ) ) {
    if ( isset( 
pb_backupbuddy::$options['profiles'][ pb_backupbuddy::_GET'profile' ) ] ) ) {
        
$profile_id pb_backupbuddy::_GET'profile' );
        
pb_backupbuddy::$options['profiles'][ pb_backupbuddy::_GET'profile' ) ] = array_mergepb_backupbuddy::settings'profile_defaults' ), pb_backupbuddy::$options['profiles'][ pb_backupbuddy::_GET'profile' ) ] ); // Set defaults if not set.
    
} else {
        
pb_backupbuddy::alert'Error #45849458: Invalid profile ID number `' htmlentitiespb_backupbuddy::_GET'profile' ) ) . '`. Displaying with default profile.'true );
    }
}


// Get profile array.
$profile array_mergepb_backupbuddy::settings'profile_defaults' ), pb_backupbuddy::$options['profiles'][$profile_id] );
foreach( 
$profile as $profile_item_name => &$profile_item ) { // replace non-overridden defaults with actual default value.
    
if ( '-1' == $profile_item ) { // Set to use default so go grab default.
        
if ( isset( pb_backupbuddy::$options['profiles'][0][ $profile_item_name ] ) ) {
            
$profile_item pb_backupbuddy::$options['profiles'][0][ $profile_item_name ]; // Grab value from defaults profile and replace with it.
        
}
    }
}




echo 
'<div style="margin-bottom: 4px;">Backup profile for calculating exclusions: ';
echo 
'<select id="pb_backupbuddy_databaseprofile" onChange="window.location.href = \'' pb_backupbuddy::page_url() . '&tab=1&profile=\' + jQuery(this).val();">';
foreach( 
pb_backupbuddy::$options['profiles'] as $this_profile_id => $this_profile ) {
    
?>
    <option value="<?php echo $this_profile_id?><?php if ( $profile_id == $this_profile_id ) { echo 'selected'; } ?>><?php echo htmlentities$this_profile['title'] ); ?>  (<?php echo $this_profile['type']; ?>)</a>
    <?php
}
echo 
'</select>';
echo 
'</div>';




//$table_list = array();
?>




<table class="widefat">
    <thead>
        <tr class="thead">
            <?php
                
echo '<th>'__('Database Table''it-l10n-backupbuddy' ),'</th>',
                     
'<th>'__('Status''it-l10n-backupbuddy' ), '</th>',
                     
'<th>'__('Settings''it-l10n-backupbuddy' ), '</th>',
                     
'<th>'__('Updated / Checked''it-l10n-backupbuddy' ),'</th>',
                     
'<th>'__('Rows''it-l10n-backupbuddy' ), '</th>',
                     
'<th>'__('Size''it-l10n-backupbuddy' ), '</th>',
                     
'<th>'__('Excluded Size''it-l10n-backupbuddy' ), '</th>';
            
?>
        </tr>
    </thead>
    <tfoot>
        <tr class="thead">
            <?php
                
echo '<th>'__('Database Table''it-l10n-backupbuddy' ),'</th>',
                     
'<th>'__('Status''it-l10n-backupbuddy' ), '</th>',
                     
'<th>'__('Settings''it-l10n-backupbuddy' ), '</th>',
                     
'<th>'__('Updated / Checked''it-l10n-backupbuddy' ),'</th>',
                     
'<th>'__('Rows''it-l10n-backupbuddy' ), '</th>',
                     
'<th>'__('Size''it-l10n-backupbuddy' ), '</th>',
                     
'<th>'__('Excluded Size''it-l10n-backupbuddy' ), '</th>';
            
?>
        </tr>
    </tfoot>
    <tbody>
        <?php
        
global $wpdb;
        
$prefix $wpdb->prefix;
        
$prefix_length strlen$wpdb->prefix );
        
        
$additional_includes explode"\n"$profile['mysqldump_additional_includes'] );
        
array_walk$additional_includescreate_function('&$val''$val = trim($val);')); 
        
$additional_excludes explode"\n"$profile['mysqldump_additional_excludes'] );
        
array_walk$additional_excludescreate_function('&$val''$val = trim($val);')); 
        
        
$total_size 0;
        
$total_size_with_exclusions 0;
        
$total_rows 0;
        
$rows $wpdb->get_results"SHOW TABLE STATUS"ARRAY_A );
        foreach( 
$rows as $row ) {
            
$excluded true// Default.
            
            // TABLE STATUS.
            
$rowsb $wpdb->get_results"CHECK TABLE `{$row['Name']}`"ARRAY_A );
            foreach( 
$rowsb as $rowb ) {
                if ( 
$rowb['Msg_type'] == 'status' ) {
                    
$status $rowb['Msg_text'];
                }
            }
            unset( 
$rowsb );
            
            
// Fix up row count and average row length for InnoDB engine which returns inaccurate
            // (and changing) values for these
            
if ( 'InnoDB' === $row'Engine' ] ) {
                if ( 
false !== ( $count $wpdb->get_var"SELECT COUNT(1) FROM `{$row'Name' ]}`" ) ) ) {
                    if ( 
< ( $row'Rows' ] = $count ) ) {
                        
$row'Avg_row_length' ] = ( $row'Data_length' ] / $row'Rows' ] );
                    }
                }
            }
            
            
// TABLE SIZE.
            
$size = ( $row['Data_length'] + $row['Index_length'] );
            
$total_size += $size;
            
            
// HANDLE EXCLUSIONS.
            
if ( $profile['backup_nonwp_tables'] == ) { // Only matching prefix.
                
if ( ( substr$row['Name'], 0$prefix_length ) == $prefix ) OR ( in_array$row['Name'], $additional_includes ) ) ) {
                    if ( !
in_array$row['Name'], $additional_excludes ) ) {
                        
$total_size_with_exclusions += $size;
                        
$excluded false;
                    }
                }
            } else { 
// All tables.
                
if ( !in_array$row['Name'], $additional_excludes ) ) {
                    
$total_size_with_exclusions += $size;
                    
$excluded false;
                }
            }
            
            
            
            
            
            
// OUTPUT TABLE ROW.
            
echo '<tr class="entry-row alternate"';
            if ( 
$excluded === true ) {
                echo 
' style="background: #fcc9c9;"';
            }
            echo 
'>';
            echo 
'    <td>' $row['Name'];
            echo 
'    <div class="row-actions">
                        <a href="' 
pb_backupbuddy::ajax_url'db_check' ) . '&table=' base64_encode$row['Name'] ) . '&#038;TB_iframe=1&#038;width=640&#038;height=600" class="thickbox" title="Check database table for any errors or corruption.">Check</a>
                        |
                        <a href="' 
pb_backupbuddy::ajax_url'db_repair' ) . '&table=' base64_encode$row['Name'] ) . '&#038;TB_iframe=1&#038;width=640&#038;height=600" class="thickbox" title="Repair table that has been corrupted. Only needed if the status or check response indicated damage.">Repair</a>
                    </div>
                '
;
            echo 
'</td>';
            echo 
'    <td>' $status '</td>';
            echo 
'    <td>Engine: ' $row['Engine'] . '<br>Collation: ' $row['Collation'] . '</td>';
            
            echo 
'    <td>Updated: ';
            if ( 
$row['Update_time'] == '' ) {
                
_e'Unavailable''it-l10n-backupbuddy' );
            } else {
                echo 
$row['Update_time'];
            }
            echo 
'<br>Checked: ';
            if ( 
$row['Check_time'] == '' ) {
                
_e'Unavailable''it-l10n-backupbuddy' );
            } else {
                echo 
$row['Check_time'];
            }
            echo 
'</td>';
            
            echo 
'    <td>' $row['Rows'] . '</td>';
            echo 
'    <td>' pb_backupbuddy::$format->file_size$size ) . '</td>';
            if ( 
$excluded === true ) {
                echo 
'    <td><span class="pb_label pb_label-important">Excluded</span></td>';
            } else {
                echo 
'    <td>' pb_backupbuddy::$format->file_size$size ) . '</td>';
            }
            
            
            
                        
            
            
            
$total_rows += $row['Rows'];
            echo 
'</tr>';
        }
        echo 
'<tr class="entry-row alternate">';
        echo 
'    <td>&nbsp;</td>';
        echo 
'    <td>&nbsp;</td>';
        echo 
'    <td>&nbsp;</td>';
        echo 
'<td><b>',__('TOTALS','it-l10n-backupbuddy' ),':</b></td>';
        echo 
'<td><b>' $total_rows '</b></td>';
        echo 
'<td><b>' pb_backupbuddy::$format->file_size$total_size ) . '</b></td>';
        echo 
'<td><b>' pb_backupbuddy::$format->file_size$total_size_with_exclusions ) . '</b></td>';
        echo 
'</tr>';
        
        
pb_backupbuddy::$options['stats']['db_size'] = $total_size;
        
pb_backupbuddy::$options['stats']['db_size_excluded'] = $total_size_with_exclusions;
        
pb_backupbuddy::$options['stats']['db_size_updated'] = time();
        
pb_backupbuddy::save();
        
        unset( 
$total_size );
        unset( 
$total_rows );
        unset( 
$rows );
        
?>
    </tbody>
</table><br>