예제 #1
0
 public function minify($cacheFile = null, $dir = null)
 {
     if ($dir === null) {
         $dir = dirname($_SERVER['SCRIPT_FILENAME']);
     }
     // MODIFICATION TIME FILES
     $mtFiles = array(__FILE__, $_SERVER['SCRIPT_FILENAME'], "conf/config.php");
     // GET SOURCE CODE FILES
     $files = dir::content($dir, array('types' => "file", 'pattern' => '/^.*\\.' . $this->type . '$/'));
     // GET NEWEST MODIFICATION TIME
     $mtime = 0;
     foreach (array_merge($mtFiles, $files) as $file) {
         $fmtime = filemtime($file);
         if ($fmtime > $mtime) {
             $mtime = $fmtime;
         }
     }
     $header = "Content-Type: {$this->mime[$this->type]}";
     // GET SOURCE CODE FROM CLIENT HTTP CACHE IF EXISTS
     httpCache::checkMTime($mtime, $header);
     // OUTPUT SOURCE CODE
     header($header);
     // GET SOURCE CODE FROM SERVER-SIDE CACHE
     if ($cacheFile !== null && file_exists($cacheFile) && (filemtime($cacheFile) >= $mtime || !is_writable($cacheFile))) {
         // with its distribution content
         readfile($cacheFile);
         die;
     }
     // MINIFY AND JOIN SOURCE CODE
     $source = "";
     foreach ($files as $file) {
         if (strlen($this->minCmd) && substr($file, 4, 1) != "_") {
             $cmd = str_replace("{file}", $file, $this->minCmd);
             $source .= `{$cmd}`;
         } else {
             $source .= file_get_contents($file);
         }
     }
     // UPDATE SERVER-SIDE CACHE
     if ($cacheFile !== null && (is_writable($cacheFile) || !file_exists($cacheFile) && dir::isWritable(dirname($cacheFile)))) {
         file_put_contents($cacheFile, $source);
         touch($cacheFile, $mtime);
     }
     // OUTPUT SOURCE CODE
     echo $source;
 }
예제 #2
0
 protected function getDirInfo($dir, $removable = false)
 {
     if (substr(basename($dir), 0, 1) == "." || !is_dir($dir) || !is_readable($dir)) {
         return false;
     }
     $dirs = dir::content($dir, array('types' => "dir"));
     if (is_array($dirs)) {
         foreach ($dirs as $key => $cdir) {
             if (substr(basename($cdir), 0, 1) == ".") {
                 unset($dirs[$key]);
             }
         }
         $hasDirs = count($dirs) ? true : false;
     } else {
         $hasDirs = false;
     }
     $writable = dir::isWritable($dir);
     $info = array('name' => stripslashes(basename($dir)), 'readable' => is_readable($dir), 'writable' => $writable, 'removable' => $removable && $writable && dir::isWritable(dirname($dir)), 'hasDirs' => $hasDirs);
     if ($dir == "{$this->config['uploadDir']}/{$this->session['dir']}") {
         $info['current'] = true;
     }
     return $info;
 }
예제 #3
0
 protected function act_mv_cbd()
 {
     $dir = $this->postDir();
     if (!$this->config['access']['files']['move'] || !isset($_POST['dir']) || !is_dir($dir) || !is_readable($dir) || !dir::isWritable($dir) || !isset($_POST['files']) || !is_array($_POST['files']) || !count($_POST['files'])) {
         $this->errorMsg("Unknown error.");
     }
     $error = array();
     foreach ($_POST['files'] as $file) {
         $file = path::normalize($file);
         if (substr($file, 0, 1) == ".") {
             continue;
         }
         $type = explode("/", $file);
         $type = $type[0];
         if ($type != $this->type) {
             continue;
         }
         $path = "{$this->config['uploadDir']}/{$file}";
         if (!$this->checkFilePath($path)) {
             continue;
         }
         $base = basename($file);
         $replace = array('file' => $this->htmlData($base));
         $ext = file::getExtension($base);
         if (!file_exists($path)) {
             $error[] = $this->label("The file '{file}' does not exist.", $replace);
         } elseif (substr($base, 0, 1) == ".") {
             $error[] = $this->htmlData($base) . ": " . $this->label("File name shouldn't begins with '.'");
         } elseif (!$this->validateExtension($ext, $type)) {
             $error[] = $this->htmlData($base) . ": " . $this->label("Denied file extension.");
         } elseif (file_exists("{$dir}/{$base}")) {
             $error[] = $this->htmlData($base) . ": " . $this->label("A file or folder with that name already exists.");
         } elseif (!is_readable($path) || !is_file($path)) {
             $error[] = $this->label("Cannot read '{file}'.", $replace);
         } elseif (!file::isWritable($path) || !@rename($path, "{$dir}/{$base}")) {
             $error[] = $this->label("Cannot move '{file}'.", $replace);
         } else {
             if (function_exists("chmod")) {
                 @chmod("{$dir}/{$base}", $this->config['filePerms']);
             }
             $fromThumb = "{$this->thumbsDir}/{$file}";
             if (is_file($fromThumb) && is_readable($fromThumb)) {
                 $toThumb = "{$this->thumbsTypeDir}/{$_POST['dir']}";
                 if (!is_dir($toThumb)) {
                     @mkdir($toThumb, $this->config['dirPerms'], true);
                 }
                 $toThumb .= "/{$base}";
                 @rename($fromThumb, $toThumb);
             }
         }
     }
     if (count($error)) {
         return json_encode(array('error' => $error));
     }
     return true;
 }