Пример #1
0
 protected function getCopyFileName($filePath)
 {
     $path = HFile::getDir($filePath);
     $files = file_exists($path) ? HFile::findFiles($path) : array();
     $files = array_flip($files);
     $ext = HFile::getExtension($this->fileName);
     $file = HFile::getFileNameByPath($this->fileName, true);
     $i = 0;
     $copyFileName = '';
     do {
         $copyFileName = $file . '(' . ++$i . ').' . $ext;
     } while (array_key_exists($copyFileName, $files));
     return $copyFileName;
 }
Пример #2
0
 /**
  * Performs the actual combining and compressing
  *
  * @param <type> $type
  * @param <type> $urls
  * @param <type> $pos
  */
 private function combineAndCompress($type, $urls, $pos)
 {
     $this->fileUrl or $this->fileUrl = $this->getCoreScriptUrl();
     $this->basePath or $this->basePath = realpath($_SERVER['DOCUMENT_ROOT']);
     $this->filePath or $this->filePath = $this->basePath . $this->fileUrl;
     $optionsHash = $type == 'js' ? md5($this->basePath . $this->compressJs . $this->ttlDays . $this->prefix) : md5($this->basePath . $this->compressCss . $this->ttlDays . $this->prefix . serialize($this->cssMinFilters + $this->cssMinPlugins));
     if ($this->autoRefresh) {
         $mtimes = array();
         foreach ($urls as $file) {
             $fileName = $this->basePath . '/' . trim($file, '/');
             if (file_exists($fileName)) {
                 $mtimes[] = filemtime($fileName);
             }
         }
         $this->_changesHash = md5(serialize($mtimes));
     }
     $combineHash = md5(implode('', $urls));
     $fileName = $this->prefix . md5($combineHash . $optionsHash . $this->_changesHash) . ".{$type}";
     $this->_renewFile = file_exists($this->filePath . '/' . $fileName) ? false : true;
     if ($this->_renewFile) {
         $this->garbageCollect($type);
         $combinedFile = '';
         $notCompress = '';
         // mixa
         foreach ($urls as $key => $file) {
             $path = str_replace('//', '/', $this->basePath . '/' . $file);
             if (!file_exists($path) && mb_strpos($path, Yii::app()->assetManager->basePath) !== false) {
                 // TODO тестовая версия
                 $dir = HFile::getDir($path);
                 HFile::removeDirectoryRecursive($dir);
                 Yii::app()->getRequest()->redirect(Yii::app()->getRequest()->getUrl());
             }
             $fileContent = file_get_contents($path);
             // mixa, обработка зависимых файлов
             $fn = basename($file);
             if (isset($this->dependResource[$fn])) {
                 $webroot = Yii::getPathOfAlias('webroot');
                 foreach ($this->dependResource[$fn] as $dependFile => $addPath) {
                     $dependFile = str_replace('\\', '/', $dependFile);
                     $dependFileName = basename($dependFile);
                     $relativePath = str_replace($webroot, "", $dependFile);
                     if (!file_exists($this->filePath . $relativePath)) {
                         $dir = dirname($this->filePath . $relativePath);
                         if (!file_exists($dir)) {
                             mkdir($dir, Yii::app()->assetManager->newDirMode, true);
                         }
                         copy($dependFile, $this->filePath . $relativePath);
                         @chmod($this->filePath . '/' . $dependFileName, Yii::app()->assetManager->newFileMode);
                     }
                     //            $fileContent = str_replace($addPath.$dependFileName, $this->fileUrl.$relativePath, $fileContent);
                     $fileContent = preg_replace('~([^a-zA-Z\\-])' . $addPath . $dependFileName . '~u', "\${1}" . $this->fileUrl . $relativePath, $fileContent);
                 }
             }
             //---
             if ($type == 'css' && strpos($fn, ".min") !== false) {
                 // mixa, почему-то уже сжатые css-файлы жмутся с ошибками (bootstrap)
                 $notCompress .= $fileContent;
             } else {
                 $combinedFile .= $fileContent;
                 if ($type == 'js') {
                     $combinedFile .= ";\n\r";
                 }
             }
         }
         if ($type == 'js' && $this->compressJs) {
             $combinedFile = $this->minifyJs($combinedFile);
         }
         if ($type == 'css' && $this->compressCss) {
             $combinedFile = $this->minifyCss($combinedFile);
         }
         file_put_contents($this->filePath . '/' . $fileName, $notCompress . $combinedFile);
     }
     foreach ($urls as $url) {
         $this->scriptMap[basename($url)] = $this->fileUrl . '/' . $fileName;
     }
     $this->remapScripts();
 }
Пример #3
0
 protected function beforeDelete()
 {
     //Рекурсивно удаляем дочерние файлы:
     $this->deleteChildFile();
     //Удаляем файл:
     HFile::removeFile($this->getFilePath());
     //Удаляем папку где был файл (если пустая)
     HFile::removeDir(HFile::getDir($this->getFilePath()));
     return parent::beforeDelete();
 }