/var/www/(Del)hsihk.com/wp-content/plugins/backupbuddy/pluginbuddy/classes/format.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



/*    class pluginbuddy_format
 *    @author Dustin Bolton
 *    
 *    Helps format content or data such as time, date, file size, etc.
 */
class pb_backupbuddy_format {
    
    
    
    
// ********** PUBLIC PROPERTIES **********
    
    
    
    // ********** PRIVATE PROPERTIES **********
    
private $_timestamp 'M j, Y g:i:s a';
    
    
    
// ********** FUNCTIONS **********
    
    
    
    /*    pluginbuddy_format->__construct()
     *    
     *    Default constructor.
     *    
     *    @return        null
     */
    
function __construct() {
    } 
// End __construct().
    
    
    
    /*    pluginbuddy_format->file_size()
     *    
     *    Takes a file size in bytes and transforms it into a human readable format with more friendly units. Decides on unit based on the size.
     *    
     *    @param        int        $size    File size.
     *    @return        string            Human formatted friendly readable format.
     */
    
function file_size$size ) {
        
$sizes = array( ' Bytes'' KB'' MB'' GB'' TB'' PB'' EB'' ZB'' YB');
        if ( 
$size == ) {
            return( 
'0 MB' );
        } else {
            return ( 
round$size pow1024, ( $i floorlog$size1024 ) ) ) ), $i 0) . $sizes[$i] );
        }
    } 
// End file_size().
    
    
    
    /*    pluginbuddy_format->date()
     *    
     *    Formats a timestamp into a nice human date format.
     *    
     *    @param        int        $timestamp        Timestamp to make pretty.
     *    @param        string    $customFormat    Custom timestamp format. Else uses $this->_timestamp defined at top of this file.
     *    @return        string                    Pretty human timestamp.
     */
    
function date$timestamp$customFormat '' ) {
        if ( 
'' == $customFormat ) {
            return 
date$this->_timestamp$timestamp );
        } else {
            return 
date$customFormat$timestamp );
        }
    } 
// End date().
    
    
    
    /*    pluginbuddy_format->unlocalize_time()
     *    
     *    Removes the timezone offset of a localized time display for a user.
     *    
     *    @param        int        $timestamp        Timestamp to remove time offset for.
     *    @return        int                        Corrected timestamp.
     */
    
function localize_time$timestamp ) {
        if ( 
function_exists'get_option' ) ) {
            
$gmt_offset get_option'gmt_offset' );
        } else {
            
$gmt_offset 0;
        }
        return 
$timestamp + ( $gmt_offset 3600 );
    } 
// End localize_time().
    
    
    
    /*    pluginbuddy_format->unlocalize_time()
     *    
     *    Removes the timezone offset of a localized time display for a user.
     *    
     *    @param        int        $timestamp        Timestamp to remove time offset for.
     *    @return        int                        Corrected timestamp.
     */
    
function unlocalize_time$timestamp ) {
        return 
$timestamp - ( get_option'gmt_offset' ) * 3600 );
    } 
// End unlocalize_time().
    
    
    
    /*    pluginbuddy_format->time_ago()
     *    
     *    Accepts NON-localized timestamps.
     *    @see time_duration
     *    
     *    @param        
     *    @return        
     */
     // TODO: deprecated?
    
function time_ago$timestamp ) {
        return 
human_time_diff$timestamptime() );
    } 
// End time_ago().
    
    
    
    /*    pluginbuddy_format->duration()
     *    
     *    Returns a human readable duration. Useful for time ago or countdowns.
     *    Ex: 5 hours, 4 minutes, 43 seconds.
     *    
     *    @param        int        $seconds        Number of seconds to turn into a human friendly readable format.
     *    @return                string            Human readable string duration.
     */
    
function time_duration$seconds ) {
        
$time time() - $seconds;
        
        
$periods = array(__('second''it-l10n-backupbuddy' ),
                         
__('minute''it-l10n-backupbuddy' ),
                         
__('hour',   'it-l10n-backupbuddy' ),
                         
__('day',       'it-l10n-backupbuddy' ),
                         
__('week',   'it-l10n-backupbuddy' ),
                         
__('month',  'it-l10n-backupbuddy' ),
                         
__('year',   'it-l10n-backupbuddy' ),
                         
__('decade''LION' )
                         );
        
$lengths = array('60','60','24','7','4.35','12','10');
        
        
$now time();
        
        
$difference $now $time;
        
$tense __('ago''it-l10n-backupbuddy' );
        
        
        for(
$j 0$difference >= $lengths[$j] && $j count($lengths)-1$j++) {
            
$difference /= $lengths[$j];
        }
        
        
$difference round($difference);
        
        if(
$difference != 1) {
            
$periods[$j].= "s";
        }
        
        return 
"$difference $periods[$j]";
    } 
// End duration().
    
    
    
    /*    prettify()
     *    
     *    Takes a string and returns a more pretty version. Looks in an array for a key matching the string.
     *    Returns the associated value. Returns original value if no pretty replacer is found.
     *    Ex:
     *        prettify( 'dog', array( 'cats' => 'Cats', 'dog' => 'Dog' ) );
     *        Returns: Dog
     *    
     *    @param        string        $value            Value to be replaced with a pretty version.
     *    @param        array        $replacements    Array of: value to look for => value to replace with.
     *    @return        string                        Pretty version that replaced $value. Returns original $value if not found in $replacements keys.
     */
    
public function prettify$value$replacements ) {
        
        if ( isset( 
$replacements[$value] ) ) { // Found replacement.
            
return $replacements[$value];
        } else { 
// No replacement; return original value.
            
return $value;
        }
        
    } 
// End prettify();
    
    
    
    /* multi_implode()
     *
     * Deep recursive implosion.
     *
     */
    
public function multi_implode($array$glue) {
        
$ret '';

        foreach (
$array as $item) {
            if (
is_array($item)) {
                
$ret .= $this->multi_implode($item$glue) . $glue;
            } else {
                
$ret .= $item $glue;
            }
        }

        
$ret substr($ret00-strlen($glue));

        return 
$ret;
    } 
// End multi_implode().
    
    
    
// End class pluginbuddy_settings.



?>