示例#1
0
function cleanNitroFiles($dir, $time)
{
    require_once NITRO_LIB_FOLDER . 'NitroFiles.php';
    $config = array('root' => realpath($dir) . DS, 'batch' => 0);
    if (!empty($time)) {
        $config['rules'][] = array('delete_time' => $time);
    }
    $files = new NitroFiles($config);
    $files->delete();
}
示例#2
0
 public function cdn_prepare_files($data)
 {
     $response =& $this->request->post['last'];
     $response['done'] = false;
     $response['response_type'] = '';
     if (empty($response['step'])) {
         $response['step'] = 'list';
     }
     $items = array();
     if (!class_exists('NitroFiles')) {
         require_once NITRO_LIB_FOLDER . 'NitroFiles.php';
     }
     // if ($response['step'] == 'prepare') {
     //     $files = new NitroFiles(array(
     //         'root' => dirname(DIR_SYSTEM)
     //     ));
     //     $response['message'] = 'Preparing file system...';
     //     $files->prepareFolders();
     //     $response['step'] = 'list';
     // } else
     if ($response['step'] == 'list') {
         if (empty($response['continue_from'])) {
             $this->cdn_init_db($data['cdn']);
             $response['continue_from'] = '';
         }
         $admin_folder = basename(DIR_APPLICATION);
         $files = new NitroFiles(array('ext' => $data['valid_extensions'], 'root' => dirname(DIR_SYSTEM), 'continue_from' => $response['continue_from'], 'debug' => $response['continue_from'] != '', 'batch' => NITRO_CDN_PREPARE_CHUNK, 'rules' => array(array('rule' => '/' . $admin_folder . '/', 'match' => false), array('rule' => '/blog\\//i', 'match' => false), array('rule' => '/\\/te?mp\\//i', 'match' => false))));
         $items = $files->find();
         if (!empty($items)) {
             $response['message'] = 'Looking for files...';
             foreach ($items as $item) {
                 $exists_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "nitro_cdn_files WHERE file='" . $this->db->escape($item['rel_path']) . "' AND uploaded=1 AND cdn=" . $data['cdn']);
                 if ($exists_query->num_rows == 0) {
                     $this->db->query("DELETE FROM " . DB_PREFIX . "nitro_cdn_files WHERE file='" . $this->db->escape($item['rel_path']) . "'");
                     $this->db->query("INSERT INTO " . DB_PREFIX . "nitro_cdn_files SET file='" . $this->db->escape($item['rel_path']) . "', size='" . $item['size'] . "', realpath='" . $this->db->escape($item['full_path']) . "', uploaded=0, cdn=" . $data['cdn']);
                 }
                 $response['message'] = 'Found ' . $item['rel_path'];
                 $response['continue_from'] = $files->getContinueFrom();
             }
         } else {
             $response['message'] = 'Starting upload...';
             $response['step'] = 'upload';
             $response['continue_from'] = '0';
             $total_query = $this->db->query("SELECT SUM(size) as total FROM " . DB_PREFIX . "nitro_cdn_files WHERE cdn=" . $data['cdn']);
             $response['all'] = $total_query->row['total'];
         }
     } elseif ($response['step'] == 'upload') {
         $items_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "nitro_cdn_files WHERE cdn=" . $data['cdn'] . " LIMIT " . (int) $response['continue_from'] . ', ' . NITRO_CDN_UPLOAD_CHUNK);
         $response['continue_from'] = (int) $response['continue_from'] + NITRO_CDN_UPLOAD_CHUNK;
         if ($items_query->num_rows) {
             $items = $items_query->rows;
         } else {
             $response['done'] = true;
         }
     }
     return $items;
 }
示例#3
0
 public function get_preminify_stack()
 {
     header('Content-Type: application/json');
     require_once NITRO_LIB_FOLDER . 'NitroFiles.php';
     $nf = new NitroFiles(array('root' => DIR_CATALOG, 'ext' => array('css', 'js')));
     $files = $nf->find();
     if (!empty($files)) {
         $files_linear = array();
         foreach ($files as $file) {
             $files_linear[] = $file['full_path'];
         }
         echo json_encode($files_linear);
     } else {
         echo json_encode(array());
     }
     exit;
 }