<?php
/**
  @licence GPL 2005-2011  The osCSS developers - osCSS Open Source E-commerce
  @portion code Copyright (c) 2002 osCommerce
  @package osCSS-2 <www http://www.oscss.org>
  @version 2.1.0
  @date  21/03/11, 18:38
  @author oscim <mail aurelien@oscim.fr> <www http://www.oscim.fr>
  @encode UTF-8
  @class clean_cache_dir
*/

class clean_cache_dir
  implements IntModCronJob{

  /**
    @var boolean active config module
  */
  public $config=false;

  public function __construct(){
  }

  /**
    @fn ClassExec()
    @brief method call by cron file. this it THE METHODE CRON
  */
  public function ClassExec($value){

    global $action,$languages_id;
    $cached_files = array();

    $dir=DIR_FS_WORK;
    foreach (scan($dir) as $file) {
      $last_modified = filemtime($dir . '/' . $file);
      if (strpos($file, '-') !== false)$code = substr($file, 0, strpos($file, '-'));
      else $code = substr($file, 0, strpos($file, '.'));

      if (isset($cached_files[$code])) {
	$cached_files[$code]['total']++;
	if ($last_modified > $cached_files[$code]['last_modified'])$cached_files[$code]['last_modified'] = $last_modified;
      } else {
	$cached_files[$code] = array('total' => 1, 'last_modified' => $last_modified,'mod'=>'FO');
      }
    }
    $dir=DIR_FS_ADMIN.DIR_WS_INCLUDES.'tmp/cache/';
    foreach (scan($dir) as $file) {
      $last_modified = filemtime($dir . '/' . $file);
      if (strpos($file, '-') !== false)$code = substr($file, 0, strpos($file, '-'));
      else $code = substr($file, 0, strpos($file, '.'));

      if (isset($cached_files[$code])) {
	$cached_files[$code]['total']++;
	if ($last_modified > $cached_files[$code]['last_modified'])$cached_files[$code]['last_modified'] = $last_modified;
      } else {
	$cached_files[$code] = array('total' => 1, 'last_modified' => $last_modified, 'pos'=>'BO');
      }
    }


      foreach($cached_files as $cache => $stats) {
	osCSS_Cache::clear($cache, (($stats['pos']=='BO')? true:false) );
      }


  }




}
?>