C:\xampp\htdocs\landing\wp-content\plugins\imagify\inc\classes\class-imagify-abstract-cron.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<?php
defined
'ABSPATH' ) || die( 'Cheatin’ uh?' );

/**
 * Basis class that handles events.
 *
 * @since  1.7
 * @author Grégory Viguier
 */
abstract class Imagify_Abstract_Cron {

    
/**
     * Class version.
     *
     * @var   string
     * @since 1.7
     */
    
const VERSION '1.0';

    
/**
     * Cron name.
     *
     * @var    string
     * @since  1.7
     * @access protected
     */
    
protected $event_name '';

    
/**
     * Cron recurrence.
     *
     * @var   string
     * @since 1.7
     * @access protected
     */
    
protected $event_recurrence '';

    
/**
     * Cron time.
     *
     * @var   string
     * @since 1.7
     * @access protected
     */
    
protected $event_time '';

    
/**
     * The single instance of the class.
     *
     * @var    object
     * @since  1.7
     * @access protected
     */
    
protected static $_instance;

    
/**
     * Get the main Instance.
     *
     * @since  1.7
     * @access public
     * @author Grégory Viguier
     *
     * @return object Main instance.
     */
    
public static function get_instance() {
        if ( ! isset( 
self::$_instance ) ) {
            
self::$_instance = new self();
        }

        return 
self::$_instance;
    }


    
/** ----------------------------------------------------------------------------------------- */
    /** INIT ==================================================================================== */
    /** ----------------------------------------------------------------------------------------- */

    /**
     * Launch hooks.
     *
     * @since  1.7
     * @access public
     * @author Grégory Viguier
     */
    
public function init() {
        
add_action'init',                       array( $this'schedule_event' ) );
        
add_action$this->get_event_name(),      array( $this'do_event' ) );
        
add_filter'cron_schedules',             array( $this'maybe_add_recurrence' ) );

        if ( 
did_action( static::get_deactivation_hook_name() ) ) {
            
$this->unschedule_event();
        } else {
            
add_action( static::get_deactivation_hook_name(), array( $this'unschedule_event' ) );
        }
    }


    
/** ----------------------------------------------------------------------------------------- */
    /** HOOKS =================================================================================== */
    /** ----------------------------------------------------------------------------------------- */

    /**
     * Initiate the event.
     *
     * @since  1.7
     * @access public
     * @author Grégory Viguier
     */
    
public function schedule_event() {
        if ( ! 
wp_next_scheduled$this->get_event_name() ) ) {
            
wp_schedule_event$this->get_event_timestamp(), $this->get_event_recurrence(), $this->get_event_name() );
        }
    }

    
/**
     * The event action.
     *
     * @since  1.7
     * @access public
     * @author Grégory Viguier
     */
    
abstract public function do_event();

    
/**
     * Unschedule the event at plugin or submodule deactivation.
     *
     * @since  1.7
     * @access public
     * @author Grégory Viguier
     */
    
public function unschedule_event() {
        
wp_clear_scheduled_hook$this->get_event_name() );
    }

    
/**
     * Add the event recurrence schedule.
     *
     * @since  1.7
     * @access public
     * @see    wp_get_schedules()
     * @author Grégory Viguier
     *
     * @param array $schedules An array of non-default cron schedules. Default empty.
     *
     * @return array
     */
    
public function maybe_add_recurrence$schedules ) {
        
$default_schedules = array(
            
'hourly'     => 1,
            
'twicedaily' => 1,
            
'daily'      => 1,
        );

        
$event_recurrence $this->get_event_recurrence();

        if ( ! empty( 
$schedules$event_recurrence ] ) || ! empty( $default_schedules$event_recurrence ] ) ) {
            return 
$schedules;
        }

        
$recurrences = array(
            
'weekly' => array(
                
'interval' => WEEK_IN_SECONDS,
                
'display'  => __'Once Weekly''imagify' ),
            ),
        );

        if ( 
method_exists$this'get_event_recurrence_attributes' ) ) {
            
$recurrences$event_recurrence ] = $this->get_event_recurrence_attributes();
        }

        if ( ! empty( 
$recurrences$event_recurrence ] ) ) {
            
$schedules$event_recurrence ] = $recurrences$event_recurrence ];
        }

        return 
$schedules;
    }


    
/** ----------------------------------------------------------------------------------------- */
    /** TOOLS =================================================================================== */
    /** ----------------------------------------------------------------------------------------- */

    /**
     * Get the cron name.
     *
     * @since  1.7
     * @access public
     * @author Grégory Viguier
     *
     * @return string
     */
    
public function get_event_name() {
        return 
$this->event_name;
    }

    
/**
     * Get the cron recurrence.
     *
     * @since  1.7
     * @access public
     * @author Grégory Viguier
     *
     * @return string
     */
    
public function get_event_recurrence() {
        
/**
         * Filter the recurrence of the event.
         *
         * @since  1.7
         * @author Grégory Viguier
         *
         * @param string $event_recurrence The recurrence.
         * @param string $event_name       Name of the event this recurrence is used for.
         */
        
return apply_filters'imagify_event_recurrence'$this->event_recurrence$this->get_event_name() );
    }

    
/**
     * Get the time to schedule the event.
     *
     * @since  1.7
     * @access public
     * @author Grégory Viguier
     *
     * @return string
     */
    
public function get_event_time() {
        
/**
         * Filter the time at which the event is triggered (WordPress time).
         *
         * @since  1.7
         * @author Grégory Viguier
         *
         * @param string $event_time A 24H formated time: `hour:minute`.
         * @param string $event_name Name of the event this time is used for.
         */
        
return apply_filters'imagify_event_time'$this->event_time$this->get_event_name() );
    }

    
/**
     * Get the timestamp to schedule the event.
     *
     * @since  1.7
     * @access public
     * @author Grégory Viguier
     *
     * @return int Timestamp.
     */
    
public function get_event_timestamp() {
        return 
self::get_next_timestamp$this->get_event_time() );
    }

    
/**
     * Get the timestamp of the next (event) date for the given hour.
     *
     * @since  1.7
     * @author Grégory Viguier
     * @source secupress_get_next_cron_timestamp()
     *
     * @param string $event_time Time when the event callback should be triggered (WordPress time), formated like `hh:mn` (hour:minute).
     *
     * @return int Timestamp.
     */
    
public static function get_next_timestamp$event_time '00:00' ) {
        
$current_time_int = (int) date'Gis' );
        
$event_time_int   = (int) str_replace':'''$event_time '00' );
        
$event_time       explode':'$event_time );
        
$event_hour       = (int) $event_time[0];
        
$event_minute     = (int) $event_time[1];
        
$offset           get_option'gmt_offset' ) * HOUR_IN_SECONDS;

        if ( 
$event_time_int <= $current_time_int ) {
            
// The event time is passed, we need to schedule the event tomorrow.
            
return mktime$event_hour$event_minute0, (int) date'n' ), (int) date'j' ) + ) - $offset;
        }

        
// We haven't passed the event time yet, schedule the event today.
        
return mktime$event_hour$event_minute) - $offset;
    }

    
/**
     * Get the deactivation hook name.
     *
     * @since  1.9
     * @access public
     * @author Grégory Viguier
     *
     * @return string
     */
    
public static function get_deactivation_hook_name() {
        static 
$deactivation_hook;

        if ( ! isset( 
$deactivation_hook ) ) {
            
$deactivation_hook 'deactivate_' plugin_basenameIMAGIFY_FILE );
        }

        return 
$deactivation_hook;
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586