/var/www/(Del)hsihk.com/wp-content/plugins/backupbuddy/lib/updater/packages.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
211
212
213
<?php

/*
Provides a reliable way of retrieving which projects have updates.
Written by Chris Jean for iThemes.com
Version 1.0.1

Version History
    1.0.0 - 2013-04-11 - Chris Jean
        Release ready
    1.0.1 - 2013-09-19 - Chris Jean
        Added support for 'upgrade' data for a package.
        Updated requires to no longer use dirname().
*/


class Ithemes_Updater_Packages {
    public static function 
flush() {
        unset( 
$GLOBALS['ithemes-updater-packages-all'] );
    }
    
    public static function 
get_full_details$response false ) {
        if ( 
false === $response ) {
            require_once( 
$GLOBALS['ithemes_updater_path'] . '/api.php' );
            
$response Ithemes_Updater_API::get_package_details();
        }
        
        
$packages self::get_local_details();
        
        
        if ( 
is_wp_error$response ) ) {
            
$expiration time() + 600;
            
            foreach ( 
$packages as $path => $data ) {
                
$packages[$path]['status'] = 'error';
                
                
$packages[$path]['error'] = array(
                    
'code'    => 'unknown',
                    
'type'    => $response->get_error_code(),
                    
'message' => $response->get_error_message(),
                );
            }
        }
        else {
            
$expiration time() + ( 12 3600 );
            
            foreach ( 
$packages as $path => $data ) {
                if ( empty( 
$response['packages'][$data['package']] ) )
                    continue;
                
                
$package $response['packages'][$data['package']];
                
                if ( ! empty( 
$package['error'] ) ) {
                    if ( 
in_array$package['error']['type'], array( 'ITXAPI_License_Key_Unknown''ITXAPI_Updater_Missing_Legacy_Key' ) ) ) {
                        
$packages[$path]['status'] = 'unlicensed';
                    }
                    else {
                        
$packages[$path]['status'] = 'error';
                        
$packages[$path]['error'] = $package['error'];
                    }
                    
                    continue;
                }
                
                
                
$key_map = array(
                    
'status'     => 'status',
                    
'link'       => 'package-url',
                    
'ver'        => 'available',
                    
'used'       => 'used',
                    
'total'      => 'total',
                    
'user'       => 'user',
                    
'sub_expire' => 'expiration',
                    
'upgrade'    => 'upgrade',
                );
                
                foreach ( 
$key_map as $old => $new ) {
                    if ( isset( 
$package[$old] ) )
                        
$packages[$path][$new] = $package[$old];
                    else
                        
$packages[$path][$new] = null;
                }
                
                if ( isset( 
$package['link_expire'] ) )
                    
$expiration min$expiration$package['link_expire'] );
            }
        }
        
        
        
$details compact'packages''expiration' );
        
        return 
$details;
    }
    
    public static function 
get_local_details() {
        require_once( 
$GLOBALS['ithemes_updater_path'] . '/keys.php' );
        
        
        
$all_packages self::get_all();
        
$keys Ithemes_Updater_Keys::get();
        
        
$packages = array();
        
        foreach ( 
$all_packages as $file => $slug )
            
$packages[$slug][] = $file;
        
        foreach ( 
$packages as $slug => $paths )
            
$packages[$slug] = array_unique$paths );
        
        
        
$details = array();
        
        
        foreach ( 
$packages as $package => $paths ) {
            foreach ( 
$paths as $path ) {
                
$plugin_path preg_replace'/^' preg_quoteWP_PLUGIN_DIR'/' ) . '/'''$path );
                
                if ( 
$plugin_path != $path ) {
                    
$type 'plugin';
                    
$rel_path preg_replace'|^[/\\\\]|'''$plugin_path );
                    
                    
$plugin_data get_plugin_data$pathfalsefalse );
                    
$version $plugin_data['Version'];
                    
$info_url $plugin_data['PluginURI'];
                }
                else {
                    
$type 'theme';
                    
$dir basenamedirname$path ) );
                    
$rel_path "$dir/" basename$path );
                    
                    if ( 
function_exists'wp_get_theme' ) ) {
                        
$theme_data wp_get_theme$dir );
                        
                        
$version $theme_data->get'Version' );
                        
$info_url $theme_data->get'ThemeURI' );
                    }
                    else {
                        
$theme_data get_theme$dir );
                        
                        
$version $theme_data['Version'];
                        
$info_url '';
                    }
                }
                
                
                
$details[$rel_path] = array(
                    
'type'        => $type,
                    
'package'     => $package,
                    
'installed'   => $version,
                    
'info-url'    => $info_url,
                    
'key'         => isset( $keys[$package] ) ? $keys[$package] : '',
                );
            }
        }
        
        
        return 
$details;
    }
    
    public static function 
get_all() {
        if ( isset( 
$GLOBALS['ithemes-updater-packages-all'] ) )
            return 
$GLOBALS['ithemes-updater-packages-all'];
        
        
        
$packages = array();
        
        
        
// Compatibility fix for WP < 3.1 as the global var is empty by default
        
if ( empty( $GLOBALS['wp_theme_directories'] ) )
            
get_themes();
        
        
$themes search_theme_directories();
        
        if ( 
is_array$themes ) ) {
            foreach ( 
$themes as $slug => $data ) {
                if ( ! 
file_exists"{$data['theme_root']}/{$data['theme_file']}) )
                    continue;
                
                
$headers get_file_data"{$data['theme_root']}/{$data['theme_file']}", array( 'package' => 'iThemes Package' ), 'theme' );
                
                if ( empty( 
$headers['package'] ) )
                    continue;
                
                
$packages["{$data['theme_root']}/{$data['theme_file']}"] = $headers['package'];
            }
        }
        
        
        require_once( 
ABSPATH 'wp-admin/includes/plugin.php' );
        
$plugins get_plugins();
        
        foreach ( 
$plugins as $file => $data ) {
            if ( ! 
file_existsWP_PLUGIN_DIR "/$file) )
                continue;
            
            
$headers get_file_dataWP_PLUGIN_DIR "/$file", array( 'package' => 'iThemes Package' ), 'plugin' );
            
            if ( empty( 
$headers['package'] ) )
                continue;
            
            
$packages[WP_PLUGIN_DIR "/$file"] = $headers['package'];
        }
        
        
        foreach ( 
$packages as $path => $package )
            
$packages[$path] = strtolower$package );
        
        
        
$GLOBALS['ithemes-updater-packages-all'] = $packages;
        
        return 
$packages;
    }
}