<?php
/**
 * VFM - veno file manager: /admin-panel/ajax/clear-share.php
 *
 * Clear /thumbnails/ folder
 *
 * PHP version >= 5.3
 *
 * @category  PHP
 * @package   VenoFileManager
 * @author    Nicola Franchini <support@veno.it>
 * @copyright 2013 Nicola Franchini
 * @license   https://veno.es/shop/help Veno Commercial License
 * @link      http://filemanager.veno.it/
 */
// Se non definita, verifichiamo se è una chiamata AJAX valida
if (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest') {
    header('HTTP/1.0 403 Forbidden');
    die('Direct access not allowed');
}
require_once dirname(dirname(__DIR__)).'/class/class.setup.php';
require_once dirname(dirname(__DIR__)).'/class/class.utils.php';
require_once dirname(dirname(__DIR__)).'/class/class.gatekeeper.php';
require_once dirname(dirname(__DIR__)).'/class/class.downloader.php';

$setUp = new SetUp();
$gateKeeper = new GateKeeper();
$downloader = new Downloader();

if (!$gateKeeper->isSuperAdmin()) {
    die('Permission Denied');
}
$get_lifetime = filter_input(INPUT_POST, 'lifetime', FILTER_VALIDATE_INT);
$lifetime = $get_lifetime ? $get_lifetime : $setUp->getConfig('lifetime');

// remove old files
$shortens = glob(dirname(dirname(__DIR__))."/_content/share/*.json");

foreach ($shortens as $shorten) {
    if (is_file($shorten)) {
        $filetime = filemtime($shorten);

        if (!$downloader->checkTime($filetime, $lifetime)) {
            unlink($shorten);
        }
    }
}
echo 'success';
exit;
