HTML
1 year ago
views
5 months ago
Apply.php
6 months ago
Cron.php
1 year ago
CronJob.php
8 months ago
CronJobs.php
2 months ago
Crypt.php
2 months ago
DownloadStats.php
5 months ago
Email.php
1 week ago
EmailCron.php
1 year ago
FileSystem.php
1 year ago
Installer.php
4 days ago
Messages.php
1 year ago
Query.php
5 months ago
Session.php
4 days ago
Settings.php
5 years ago
SimpleMath.php
5 years ago
TempStorage.php
4 days ago
Template.php
5 months ago
UI.php
6 months ago
Updater.php
4 years ago
UserAgent.php
2 years ago
__.php
2 months ago
__MailUI.php
3 years ago
CronJobs.php
107 lines
| 1 | <?php |
| 2 | /** |
| 3 | * User: shahjada |
| 4 | * Date: 2019-03-21 |
| 5 | * Time: 13:14 |
| 6 | */ |
| 7 | |
| 8 | namespace WPDM\__; |
| 9 | |
| 10 | |
| 11 | class CronJobs |
| 12 | { |
| 13 | private static $instance; |
| 14 | |
| 15 | public static function getInstance() |
| 16 | { |
| 17 | if (self::$instance === null) { |
| 18 | self::$instance = new self; |
| 19 | } |
| 20 | return self::$instance; |
| 21 | } |
| 22 | function __construct() |
| 23 | { |
| 24 | |
| 25 | add_filter( 'cron_schedules', array($this, 'interval') ); |
| 26 | add_action( 'init', array($this, 'clearTempDataCPCron') ); |
| 27 | add_action( 'init', array($this, 'deleteExpired') ); |
| 28 | add_action( 'init', array($this, 'cronCheck') ); |
| 29 | |
| 30 | if ( ! wp_next_scheduled( '__wpdm_cron' ) ) { |
| 31 | wp_schedule_event( time() + 3600, 'six_hourly', '__wpdm_cron' ); |
| 32 | } |
| 33 | |
| 34 | $this->schedule(); |
| 35 | |
| 36 | } |
| 37 | |
| 38 | function cronCheck() { |
| 39 | if(wpdm_query_var('wpdm_cron', 'int')) { |
| 40 | if(!isset($_REQUEST['cronkey']) || $_REQUEST['cronkey'] !== WPDM()->cronJob->cronKey()) return; |
| 41 | $cronJob = new CronJob(); |
| 42 | $cronJob->executeAll(); |
| 43 | do_action('wpdm_cron_job'); |
| 44 | die('Completed'); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | function interval( $schedules ) { |
| 49 | $schedules['six_hourly'] = array( |
| 50 | 'interval' => 21600, //6 hours |
| 51 | 'display' => esc_html__( 'Every 6 hours' ), |
| 52 | ); |
| 53 | |
| 54 | return $schedules; |
| 55 | } |
| 56 | |
| 57 | function schedule(){ |
| 58 | add_action( '__wpdm_cron', array($this, 'clearTempData') ); |
| 59 | } |
| 60 | |
| 61 | function clearTempData(){ |
| 62 | if(!(int)get_option('__wpdm_auto_clean_cache', 0)) return; |
| 63 | global $wpdb; |
| 64 | $time = time(); |
| 65 | $wpdb->query("delete from {$wpdb->prefix}ahm_sessions where `expire` < $time"); |
| 66 | FileSystem::deleteFiles(WPDM_CACHE_DIR, false, '.zip'); |
| 67 | FileSystem::deleteFiles(WPDM_CACHE_DIR, false, array('filetime' => time() - 3600, 'ext' => '.txt')); |
| 68 | //FileSystem::deleteFiles(WPDM_CACHE_DIR . 'pdfthumbs/', false); |
| 69 | } |
| 70 | |
| 71 | function clearTempDataCPCron(){ |
| 72 | if(!isset($_REQUEST['cpc']) || !isset($_REQUEST['cronkey']) || $_REQUEST['cpc'] !== 'wpdmcc') return; |
| 73 | |
| 74 | if($_REQUEST['cronkey'] !== WPDM()->cronJob->cronKey()) return; |
| 75 | |
| 76 | global $wpdb; |
| 77 | $time = time(); |
| 78 | $wpdb->query("delete from {$wpdb->prefix}ahm_sessions where `expire` < $time"); |
| 79 | FileSystem::deleteFiles(WPDM_CACHE_DIR, false, '.zip'); |
| 80 | FileSystem::deleteFiles(WPDM_CACHE_DIR, false, array('filetime' => time() - 3600, 'ext' => '.txt')); |
| 81 | die('Cache cleared successfully!'); |
| 82 | } |
| 83 | |
| 84 | function deleteExpired(){ |
| 85 | |
| 86 | if(!isset($_REQUEST['cde']) || !isset($_REQUEST['cronkey']) || $_REQUEST['cde'] !== 'wpdmde') return; |
| 87 | if($_REQUEST['cronkey'] !== WPDM()->cronJob->cronKey()) return; |
| 88 | |
| 89 | if(!(int)get_option('__wpdm_delete_expired', 0)) return; |
| 90 | |
| 91 | global $wpdb; |
| 92 | $today = date("YmdHi"); |
| 93 | $res = $wpdb->get_results("select post_id, meta_value as expire_date from {$wpdb->prefix}postmeta where meta_key = '__wpdm_expire_date' and meta_value <> ''"); |
| 94 | $deleted = 0; |
| 95 | foreach ($res as $item) { |
| 96 | $time = strtotime($item->expire_date); |
| 97 | if($time < time() && get_post_status($item->post_id) == 'publish') { |
| 98 | wp_trash_post($item->post_id); |
| 99 | $deleted++; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | wp_send_json(['success' => true, 'delete_expired' => $deleted]); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 |