Code

Update FAQ
[gosa.git] / gosa-core / update-gosa
index be1de84a2d90655e40ba4101bbf61538b427f95e..13f2f78e5c7639661dc12cd55c83e9767f83ce35 100755 (executable)
@@ -2,7 +2,7 @@
 <?php
 /*
  * This code is part of GOsa (http://www.gosa-project.org)
- * Copyright (C) 2003-2008 GONICUS GmbH
+ * Copyright (C) 2003-2010 GONICUS GmbH
  *
  * ID: $$Id: main.php 9254 2008-03-03 15:57:49Z cajus $$
  *
@@ -39,6 +39,8 @@ Usage: update-gosa install dsc     Install the plugin using the dsc information
 
        update-gosa rescan-i18n     Rebuilds the translations
 
+       update-gosa rescan-images   Rebuilds the themes master image
+
        update-gosa rescan-classes  Rebuilds the class list
        
        update-gosa                 Shortcut for rescan-classes and rescan-i18n
@@ -61,6 +63,20 @@ function rmdirRecursive($path, $followLinks=false) {
 }
 
 
+function get_themes()
+{
+  $themes= array();
+  $d = dir(GOSA_HOME."/html/themes");
+  while (false !== ($entry = $d->read())) {
+    if ($entry[0] != '.') {
+      $themes[]= basename($entry);
+    }
+  }
+  $d->close();
+
+  return $themes;
+}
+
 /* Function to include all class_ files starting at a given directory base */
 function get_classes($folder= ".")
 {
@@ -81,7 +97,7 @@ function get_classes($folder= ".")
   }
 
   $dh = opendir(".");
-  while(false !== ($file = readdir($dh))){
+  while(is_resource($dh) && false !== ($file = readdir($dh))){
 
     if (preg_match("/.*\.svn.*/", $file) ||
         preg_match("/.*smarty.*/i",$file) ||
@@ -91,7 +107,7 @@ function get_classes($folder= ".")
     }
 
     /* Recurse through all "common" directories */
-    if (is_dir($file)){
+    if (is_dir($file) && !file_exists("{$file}/excludeFromAutoLoad")){
       get_classes($file);
       continue;
     }
@@ -112,7 +128,7 @@ function get_classes($folder= ".")
     }
   }
 
-  closedir($dh);
+  @closedir($dh);
   chdir($currdir);
 
   return ($result);
@@ -535,6 +551,8 @@ function rescan_images($path, $theme)
   $styles= array();
   $duplicates= array();
 
+  echo "Updating master image for theme '$theme'...";
+
   // Check for image magick convert
   if (!function_exists("imageFilter")){
     exec("which convert", $res, $ret);
@@ -544,27 +562,26 @@ function rescan_images($path, $theme)
   }
   
   // Scan for images in the given path
-  echo "Scanning for images";
   flush();
   foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)) as $fileInfo) {
   
       // We're only interested in png files
       $indexPath= substr($fileInfo->getPathname(), $baseLength + 1);
       $path= $fileInfo->getPathname();
-      if (preg_match('/\.png$/', $indexPath) && !preg_match('/\.svn/', $path) && !preg_match('/themes\/[^\/]+\/img.png$/', $path)){
+      if (preg_match('/\.png$/', $indexPath) && !preg_match('/\.svn/', $path) && !preg_match('/themes\/[^\/]+\/images\/img.png$/', $path)){
   
          // Grey image if it is not already one
          if (preg_match('/grey/', $indexPath)) {
            echo "!";
-           $warnings[]= "Warning: skipped possible grey image $path";
+           $warnings[]= "! Warning: skipped possible *grey* image $path";
            flush();
            continue;
          }
 
-         // Grey image if it is not already one
-         if (preg_match('/new/', $indexPath)) {
+         // New image if it is not already one
+         if (preg_match('/new/', $indexPath) && !preg_match('/new\.png$/', $indexPath)) {
            echo "!";
-           $warnings[]= "Warning: skipped possible grey image $path";
+           $warnings[]= "! Warning: skipped possible *new* image $path";
            flush();
            continue;
          }
@@ -584,7 +601,7 @@ function rescan_images($path, $theme)
          // Is this image already there?
          $checksum= md5_file($path);
          if (in_array($checksum, $checksums)) {
-           $warnings[]= "Warning: images $indexPath seems to be a duplicate of ".array_search($checksum, $checksums);
+           $warnings[]= "Warning: images $indexPath seems to be a duplicate of ".array_search($checksum, $checksums);
            $duplicates[$indexPath]= array_search($checksum, $checksums);
            $duplicates[$greyIndexPath]= preg_replace('/\.png$/', '-grey.png', array_search($checksum, $checksums));
            continue;
@@ -687,7 +704,7 @@ function rescan_images($path, $theme)
     // Move X cursor to the next position
     $cursorX+= $imageWidth;
 
-    $maxX=($colX > $maxX)?$colX:$maxX;
+    $maxX=($colX+$imageWidth > $maxX)?$colX+$imageWidth:$maxX;
   }
   
   // Print maximum dimensions
@@ -710,7 +727,7 @@ function rescan_images($path, $theme)
 
     // Insert source image...
 
-    // And eventually convert it to grey before
+    // Eventually convert it to grey before
     if (preg_match('/-grey\.png$/', $imagePath)) {
       if (!function_exists("imageFilter")){
         exec("convert ".$paths[$imagePath]." -colorspace Gray /tmp/grey-converted.png");
@@ -727,14 +744,6 @@ function rescan_images($path, $theme)
     imageCopyResampled($dst, $src, $x, $y, 0, 0, $imageWidth, $imageHeight, $imageWidth, $imageHeight);
     imageDestroy($src);
 
-    // Eventually overload with grey part
-    if (isset($duplicates[$imagePath])){
-      $imageHeight= $heights[$duplicates[$imagePath]];
-      $imageWidth= $widths[$duplicates[$imagePath]];
-      $x= $posX[$duplicates[$imagePath]];
-      $y= $posY[$duplicates[$imagePath]];
-    }
-
     // Store style
     $styles[$imagePath]= "background-position:-".$x."px -".$y."px;width:".$imageWidth."px;height:".$imageHeight."px";
 
@@ -742,7 +751,12 @@ function rescan_images($path, $theme)
     flush();
   }
 
-  imagePNG($dst, "html/themes/$theme/img.png", 9);
+  /* Add duplicates */
+  foreach ($duplicates as $imagePath => $realPath) {
+    $styles[$imagePath]= $styles[$realPath];
+  }
+
+  imagePNG($dst, GOSA_HOME."/html/themes/$theme/images/img.png", 9);
   imageDestroy($dst);
 
   // Show warnings images
@@ -752,7 +766,7 @@ function rescan_images($path, $theme)
 
   // Write styles
   echo "Writing styles...";
-  $fp = fopen("ihtml/themes/$theme/img.styles", 'w');
+  $fp = fopen(GOSA_HOME."/ihtml/themes/$theme/img.styles", 'w');
   fwrite($fp, serialize($styles));
   fclose($fp);
 
@@ -768,8 +782,10 @@ if ($argc < 2){
        rescan_classes();
        rescan_i18n();
        rescan_guide();
-        rescan_images("html", "modern");
-        exit (0);
+    foreach (get_themes() as $theme) {
+      rescan_images(GOSA_HOME."/html", $theme);
+    }
+    exit (0);
 }
 
 switch ($argv[1]){
@@ -799,7 +815,9 @@ switch ($argv[1]){
                 rescan_classes();
                 break;
         case 'rescan-images':
-                rescan_images("html", "modern");
+                foreach (get_themes() as $theme) {
+                  rescan_images("html", $theme);
+                }
                 break;
         default:
                 echo "Error: Supplied command not known\n\n";