Пример #1
0
function RemoveEmptySubFolders($path)
{
    $empty = true;
    foreach (glob($path . DIRECTORY_SEPARATOR . "*") as $file) {
        $empty &= is_dir($file) && RemoveEmptySubFolders($file);
    }
    return $empty && rmdir($path);
}
Пример #2
0
 protected function cleanTheme($post)
 {
     //Compare files in core views with files in our theme, and remove any theme files that match
     //to let the master files bleed through
     $original = Yii::app()->theme->name;
     $arrConfig = $this->loadConfiguration($original);
     if (isset($arrConfig['parent']) && !is_null($arrConfig['parent'])) {
         $viewset = Yii::app()->theme->info->viewset;
         if (empty($viewset)) {
             $viewset = "cities";
         }
         $viewset = "/views-" . $viewset;
         $path = Yii::getPathOfAlias('application') . $viewset;
         $fileArray = $this->getFilesFromDir($path);
         $ct = 0;
         foreach ($fileArray as $filename) {
             if (stripos($filename, "/site/index.php") === false) {
                 $localthemefile = str_replace("core/protected" . $viewset, "themes/{$original}/views", $filename);
                 if (file_exists($localthemefile) && md5_file($filename) == md5_file($localthemefile)) {
                     unlink($localthemefile);
                     $ct++;
                 }
             }
         }
         $path = YiiBase::getPathOfAlias('webroot') . "/themes/" . $original . "/views";
         RemoveEmptySubFolders($path);
         Yii::app()->user->setFlash('warning', Yii::t('admin', '{fcount} files were unmodified from the original and have been cleared out of {theme}', array('{fcount}' => $ct, '{theme}' => ucfirst($original), '{time}' => date("d F, Y  h:i:sa"))));
         return $this->changeTheme($post);
     } else {
         Yii::app()->user->setFlash('error', Yii::t('admin', 'Clean can only be applied to a copy of a theme. {theme} was not modified.', array('{theme}' => ucfirst($original), '{time}' => date("d F, Y  h:i:sa"))));
         return $this->changeTheme($post);
     }
 }