<?php
if( ! defined( 'DATALIFEENGINE' ) ) {die( "Hacking attempt!" );}

$cron = false;
$_TIME = time () + ($config['date_adjust'] * 60);

$cron_time = $cache->get ( "cron" );
if (date ( "Y-m-d", $cron_time ) != date ( "Y-m-d", $_TIME )) $cron = true;

if($cron) {
    $cache->set( "cron", $_TIME );

	$db->query( "DELETE FROM " . USERPREFIX . "_banned WHERE days != '0' AND date < '$_TIME' AND users_id = '0'" );
	$cache->delete('banned.php' );

    if( intval( $config['max_image_days'] ) ) {
		$thisdate = $_TIME - ($config['max_image_days'] * 3600 * 24);
		$db->query( "SELECT images  FROM " . PREFIX . "_images where date < '$thisdate' AND news_id = '0'" );
		while ( $row = $db->get_row() ) {
			$listimages = explode( "|||", $row['images'] );
			if( $row['images'] != "" ) foreach ( $listimages as $dataimages ) {
				$url_image = explode( "/", $dataimages );
				if( count( $url_image ) == 2 ) {
					$folder_prefix = $url_image[0] . "/";
					$dataimages = $url_image[1];
				} else {
					$folder_prefix = "";
					$dataimages = $url_image[0];
				}
				@unlink( ROOT_DIR . "/uploads/posts/" . $folder_prefix . $dataimages );
				@unlink( ROOT_DIR . "/uploads/posts/" . $folder_prefix . "thumbs/" . $dataimages );
			}}
		$db->free();
		$db->query( "DELETE FROM " . PREFIX . "_images where date < '$thisdate' AND news_id = '0'" );
	}
    $cache->clear();
}
?>