GIT repositories

Index page of all the GIT repositories that are clonable form this server via HTTPS. Übersichtsseite aller GIT-Repositories, die von diesem Server aus über git clone (HTTPS) erreichbar sind.

Services

A bunch of service scripts to convert, analyse and generate data. Ein paar Services zum Konvertieren, Analysieren und Generieren von Daten.

GNU octave web interface

A web interface for GNU Octave, which allows to run scientific calculations from netbooks, tables or smartphones. The interface provides a web form generator for Octave script parameters with pre-validation, automatic script list generation, as well presenting of output text, figures and files in a output HTML page. Ein Webinterface für GNU-Octave, mit dem wissenschaftliche Berechnungen von Netbooks, Tablets oder Smartphones aus durchgeführt werden können. Die Schnittstelle beinhaltet einen Formulargenerator für Octave-Scriptparameter, mit Einheiten und Einfabevalidierung. Textausgabe, Abbildungen und generierte Dateien werden abgefangen und in einer HTML-Seite dem Nutzer als Ergebnis zur Verfügung gestellt.

ZIP Datei Wrapper - Klasse

ZIP file wrapper class

I was a little bit fed up with the situation that I have to organize too much around the ZipArchive class. So, here is a wrapper for this class, which applies to the usual tasks you have for zip files (compress recursive, extract recursive, look what's inside etc.). The class ZipFile does not return error, but instead throws exceptions, which is (so I think) more elaborated. Notice, that if you should put the ZipException in a separate file for autoloading. File contents of ZipException.class.php and ZipFile.class.php:

Es ging mir einfach irgendwann auf den Keks, dass ich bei der Verwendung der Klasse ZipArchive viel Organisationsaufwand drumrum hatte - es musste ein brauchbarer Wrapper mit Exceptions her. Die anbei gezeigte Klasse ZipFile unterstützt die normalen Aufgaben, welche man für zips so kennt (komprimieren, dekomprimieren, schauen was drin ist). Bitte beachte, dass die Exception-Klasse in einer separaten Datei gespeichert wird, wenn Autoloading verwendet wird. Inhalte der Dateien ZipException.class.php und ZipFile.class.php:

Class source code

Klassen-Quelltext

<?php
 
/**
 * Exception thrown by class ZipFile
 * @gpackage de.atwillys.sw.php.swLib
 * @author Stefan Wilhelm
 * @copyright Stefan Wilhelm, 2007-2010
 * @license GPL
 * @version 1.0
 */
 
namespace sw;
 
class ZipException extends LException {
 
}
<?php
 
/**
 * Wrapper class for ZipArchive with exceptions. Provides simple functions
 * to compress, list and extract files or folders (recursively).
 * @gpackage de.atwillys.sw.php.swLib
 * @author Stefan Wilhelm
 * @copyright Stefan Wilhelm, 2007-2010
 * @license GPL
 * @version 1.0
 * @uses ZipException
 */
 
namespace sw;
 
class ZipFile {
 
  /**
   * The zip object
   * @var ZipArchive
   */
  private $zip = null;
 
  /**
   * Constructor
   * @return ZipFile
   */
  public final function __construct() {
    $this->zip = new ZipArchive();
  }
 
  /**
   * Destructor
   */
  public final function __destruct() {
    $this->close();
  }
 
  /**
   * Throws an ZipException according to the occurred ZipArchive
   * error code.
   * @static
   * @param int $zipArchiveErrorCode
   * @throws ZipException
   * @return void
   */
  private static final function throwZipException($zipArchiveErrorCode) {
    switch ($zipArchiveErrorCode) {
      case ZIPARCHIVE::ER_EXISTS:
        throw new ZipException('Zip file already exists');
      case ZIPARCHIVE::ER_OPEN:
        throw new ZipException('Failed to open zip file');
      case ZIPARCHIVE::ER_READ:
        throw new ZipException('Could not read zip file');
      case ZIPARCHIVE::ER_INCONS:
        throw new ZipException('Zip file inconsistent');
      case ZIPARCHIVE::ER_INVAL:
        throw new ZipException('Zip file invalid');
      case ZIPARCHIVE::ER_MEMORY:
        throw new ZipException('Not enough memory to handle zip file');
      case ZIPARCHIVE::ER_NOENT:
        throw new ZipException('Zip file has no entries');
      case ZIPARCHIVE::ER_NOZIP:
        throw new ZipException('File is no zip file');
      case ZIPARCHIVE::ER_SEEK:
        throw new ZipException('Could seek the position in zip file');
      default:
        throw new ZipException('Unknown error occurred handling zip file');
    }
  }
 
  /**
   * Generates a new zip file from a file or a folder. Folders are
   * compressed recursively.
   * @param string $fileOrFolder
   * @param string $zipArchive
   * @return string
   */
  public static function compress($fileOrFolder, $zipArchive) {
    $zip = new self();
    $zip->create($zipArchive);
    try {
      $zip->add($fileOrFolder);
    } catch (\Exception $e) {
      $zip->close();
      @unlink($zipArchive);
      throw $e;
    }
    $zip->close();
    return realpath($zipArchive);
  }
 
  /**
   * Extracts a file or folder to a specified location folder.
   * The folder must exist before extracting
   * @param string $zipArchive
   * @param string $folder
   */
  public static function extract($zipArchive, $folder) {
    if (!is_dir($folder)) {
      throw new ZipException('Directory to extract to does not exist');
    } else {
      $zip = new self();
      $zip->open($zipArchive);
      $e = $zip->zip->extractTo($folder);
      if (!$e) {
        $zip->close();
        throw new ZipException('Failed to extract files');
      }
      $zip->close();
    }
  }
 
  /**
   * Returns an assoc. array containing the list of all entries in the zip archive.
   * Each entry is an assoc. array that contains details about the file/folder.
   * @return array
   */
  public static function contents($zipArchive) {
    $zip = new self();
    $zip->open($zipArchive);
    $l = $zip->getContentList();
    $zip->close();
    return $l;
  }
 
  /**
   * Opens a zip file for manipulation and returns
   * the ZipFile object for the opened file.
   * @param string $file
   * @throws ZipException
   * @return void
   */
  public function open($file) {
    if (!is_file($file)) {
      throw new ZipException('Zip file to open does not exist');
    } else if (!is_readable($file)) {
      throw new ZipException('Zip file to open is not readable');
    } else {
      $e = $this->zip->open($file);
      if ($e !== true) {
        self::throwZipException($e);
      }
    }
  }
 
  /**
   * Creates and opens a zip file for manipulation and returns
   * the ZipFile object for the created file.
   * @static
   * @param string $file
   * @throws ZipException
   * @return void
   */
  public function create($file) {
    if (is_file($file)) {
      throw new ZipException('Zip file to create already exists');
    } else {
      $e = $this->zip->open($file, ZipArchive::CREATE);
      if ($e !== true) {
        self::throwZipException($e);
      }
    }
  }
 
  /**
   * Closes the zip file
   */
  public function close() {
    try {
      @$this->zip->close();
    } catch (\Exception $e) {
      // ignore here
    }
  }
 
  /**
   * Adds a file or a directory (recursive) to the zip archive. The $basePath
   * indicates the root directory of the archive. If e.g. $pathToFileOrDir
   * is "/tmp/folder1/folder2/file.txt" and $basePath is "/tmp/folder1", then
   * the file.txt will be in the archive as "/folder2/file.txt".
   * @param string $pathToFileOrDir
   * @param string $basePath
   */
  public function add($pathToFileOrDir, $basePath=null) {
    $pathToFileOrDir = trim($pathToFileOrDir);
    $basePath = trim($basePath);
    Tracer::trace("add '$pathToFileOrDir', basepath '$basePath'");
 
    if (!is_file($pathToFileOrDir) && !is_dir($pathToFileOrDir)) {
      throw new ZipException('File or directory to add does not exist in file system');
    } else {
      if (empty($basePath)) {
        // Assume that the file/directory is to be added to the zip root
        $basePath = dirname($pathToFileOrDir);
      }
      if (stripos($pathToFileOrDir, $basePath) === false) {
        throw new ZipException('The path to the file or directory must include base path');
      }
 
      // Create local path for zip
      if (is_file($pathToFileOrDir)) {
        $localPath = str_ireplace($basePath, '', $pathToFileOrDir);
        // Check if the directory structure already exist in the zip file
        if (dirname($localPath) != '') {
          $e = $this->zip->addEmptyDir(dirname($localPath));
          if ($e !== true && $e != ZipArchive::ER_EXISTS) {
            self::throwZipException($e);
          }
        }
        // Finally add the file
        $e = $this->zip->addFile($pathToFileOrDir, $localPath);
        if ($e !== true) {
          self::throwZipException($e);
        }
      } else if (is_dir($pathToFileOrDir)) {
        // Add a directory
        $content = FileSystem::find($pathToFileOrDir, '*');
        foreach ($content as $file) {
          $localPath = str_ireplace($basePath, '', $file);
          if (is_dir($file)) {
            $e = $this->zip->addEmptyDir($localPath);
            if ($e !== true && $e != ZipArchive::ER_EXISTS) {
              self::throwZipException($e);
            }
          } else {
            $e = $this->zip->addFile($file, $localPath);
            if ($e !== true) {
              self::throwZipException($e);
            }
          }
        }
      }
    }
  }
 
  /**
   * Removes a file or a folder in the zip file
   * @param string $fileOrFolderInZip
   */
  public function remove($fileOrFolderInZip) {
    $fileOrFolderInZip = trim($fileOrFolderInZip);
    if (strlen($fileOrFolderInZip) == 0) {
      throw new ZipException('No file or folder to delete given');
    } else if ($fileOrFolderInZip == '/') {
      throw new ZipException('Cannot delete the root of zip file');
    } else {
 
      print "$fileOrFolderInZip\n\n\n";
      if (!$this->zip->deleteName($fileOrFolderInZip)) {
        throw new ZipException('Failed to remove file/folder in zip archive');
      }
    }
  }
 
  /**
   * Returns an assoc. array containing the list of all entries in the zip archive.
   * Each entry is an assoc. array that contains details about the file/folder.
   * @return array
   */
  public function getContentList() {
    $stats = array();
    for ($i = 0; $i < $this->zip->numFiles; $i++) {
      $stat = $this->zip->statIndex($i);
      if (!is_array($stat)) {
        throw new ZipException('Failed to receive the status or a contained file or folder');
      } else {
        $stats[$stat['name']] = $stat;
      }
    }
    return $stats;
  }
 
}