Вход Регистрация
Файл: adultscript-2.0.3-pro/files/cron/cron.php
Строк: 78
<?php
define
('_VALID'true);

$base_dir realpath(dirname(__FILE__).'/../');
require 
$base_dir.'/libraries/bootstrap.php';

$secret    = (isset($_GET['secret'])) ? trim($_GET['secret']) : '';
if (
php_sapi_name() == 'cli' && isset($_SERVER['argv']) && isset($_SERVER['argv']['1'])) {
    
$secret    trim($_SERVER['argv']['1']);
}

// we only allow this script to be executed if the password is set correctly
if ($secret != md5(VF::cfg_item('secret'))) {
    
VLog::add('CRON: called with empty or incorrect code! Aborting...');
    exit;
}

set_time_limit(0);

function 
seconds_to_time($seconds)
{
    
$format    = ($seconds >= 86400) ? 'd H:i:s' 'H:i:s';
    return 
date($formatmktime(00$seconds00));
}

function 
update_script($script_name$utime=TRUE$status=FALSE)
{
    
VF::factory_remove('database');
    
$db    VF::factory('database');
    
    
$time    time();
    if (
$utime === TRUE) {
        
$db->query("UPDATE #__cron
                    SET exec_time = "
.$time.",
                        exec_status = '0'
                    WHERE slug = '"
.$db->escape($script_name)."'
                    LIMIT 1"
);
    }
    
    if (
$status === TRUE) {
        
$db->query("UPDATE #__cron
                    SET exec_status = '1'
                    WHERE slug = '"
.$db->escape($script_name)."'
                    LIMIT 1"
);
    }
    
    
VLog::add('Updated script: '.$script_name.', time: '.$time.', status: '.(int) $status);
}

VLog::add('Starting cron execution...');

$db             VF::factory('database');
if (isset(
$_GET['id'])) {
    
$db->query("SELECT cron_id, module, slug, status,
                   period, exec_time, exec_status
                  FROM #__cron
                  WHERE cron_id = "
.(int) trim($_GET['id'])."
                  AND status = 1
                  ORDER BY cron_id ASC"
);
} else {
    
$db->query("SELECT cron_id, module, slug, status,
                   period, exec_time, exec_status
                  FROM #__cron
                  WHERE status = 1
                  ORDER BY cron_id ASC"
);    
}

if (!
$db->affected_rows()) {
    
VLog::add('Failed to fetch any scripts for execution!');
    exit;
}

$scripts    $db->fetch_rows();
$time        time();

foreach (
$scripts as $script) {
    if (
VModule::enabled($script['module'])) {
        
$slug            $script['slug'];
        
$period            = (int) $script['period'];
        
$period_seconds    $period*60;
        
$exec_time        = (int) $script['exec_time'];
        
$exec_status    = (int) $script['exec_status'];
        
$status            = (int) $script['status'];
    
        
VLog::add('Script: '.$slug.', period: every '.$period.' minutes ('.seconds_to_time($period_seconds).'), status: '.$status);
        
VLog::add('Script: '.$slug.' last run on: '.date('Y-m-d H:i:s'$exec_time).' with status: '.$exec_status);
    
        if (
$status === 0) {
            
// dont run script if status is 0
            
continue;
        }
          
        
$execute    TRUE;
        
$current    time();
        if (
$exec_status === 1) {
            
// we only check the period if the execution status was 1
            
$passed    $exec_time $period_seconds;
            if (
$passed $current) {
                
VLog::add('Not running script '.$slug.' (offset: '.seconds_to_time($passed $current).')!');
                
$execute    false;
            }
        }            

        if (
$execute === true) {
            
VLog::add('Running script: '.$slug);
            
$script_file        BASE_DIR.'/cron/scripts/'.$slug.'.php';
            
$script_function    'cron_'.$slug;
                
            if (!
function_exists($script_function)) {
                require 
$script_file;
            }
                
            
$script_function();
        }
    } else {
        
VLog::add('Module '.$module.' not enabled! No cron execution (script: '.$script['slug'].')!');
    }
}

VF::close();
?>
Онлайн: 0
Реклама