Location: PHPKode > projects > ZZ/OSS Installer > zic-1.1.0dev1/installer/lib/ZZOSS_File/File.php
<?php 
    /*
    Copyright (C) 2001-2004 ZZOSS GbR, http://www.zzoss.com

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    */
    
    /**
    @version $Id: File.php,v 1.2 2004/04/05 11:51:12 ordnas Exp $
    @copyright Copyright &copy; 2001-2004 ZZ/OSS GbR, http://www.zzoss.com
    @license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License
    */
    
/**
* Helper methods for several occasions.
*/
class ZZOSS_File
{

	/**
    * serializes $var and dumps it
	* to disk
    */
	function serialize($file, $var) {
		$fp = fopen($file, "w");
		fwrite($fp, serialize($var));
		fclose($fp);
	}
	
	/**
    * reads a serialized dump from disk
	* and returns it unserialized
    */
	function unserialize($file) {
		if(file_exists($file)){
		  	$fp = fopen($file,"r");
			$ser = fread ($fp, filesize ($file));
			fclose($fp);  
			return unserialize($ser);
		}
	}
    
	/* 
	 * Replaces special chars of a string to make the string compatible with 
	 * filename conventions. 
	 */ 
	function convertToFilename($title) 
	{ 
		$nametitle = strtolower($title); 
		$nametitle = str_replace('Ä','ae',$nametitle); 
		$nametitle = str_replace('Ö','oe',$nametitle); 
		$nametitle = str_replace('Ü','ue',$nametitle); 
		$nametitle = str_replace('?','_',$nametitle); 
		$nametitle = str_replace('\'','_',$nametitle); 
		$nametitle = str_replace("´",'_',$nametitle); 
		$nametitle = str_replace('&','_',$nametitle); 
		$nametitle = str_replace('+','_',$nametitle); 
		$nametitle = str_replace('$','_',$nametitle); 
		$nametitle = str_replace('-','_',$nametitle); 
		$nametitle = str_replace('%','_',$nametitle); 
		$nametitle = str_replace("'",'_',$nametitle); 
		$nametitle = str_replace('&','_',$nametitle); 
		$nametitle = str_replace('<','_',$nametitle); 
		$nametitle = str_replace('>','_',$nametitle); 
		$nametitle = str_replace(' ','_',$nametitle); 
		$nametitle = str_replace('§','_',$nametitle); 
		$nametitle = str_replace('&','_',$nametitle); 
		$nametitle = str_replace('€ ','e',$nametitle); 
		$nametitle = str_replace('ä','ae',$nametitle); 
		$nametitle = str_replace('ö','oe',$nametitle); 
		$nametitle = str_replace('ü','ue',$nametitle); 
		$nametitle = str_replace('/','_',$nametitle); 
		$nametitle = str_replace('\\','_',$nametitle); 
		$nametitle = str_replace('ß','_',$nametitle); 
		//$nametitle = str_replace('.','_',$nametitle); 
		$nametitle = str_replace(':','_',$nametitle); 
		$nametitle = str_replace('#','_',$nametitle); 
		$nametitle = str_replace('*','_',$nametitle); 
		$nametitle = str_replace('~','_',$nametitle); 
		$nametitle = str_replace('"','_',$nametitle); 
		 
		return($nametitle); 
	}
    
    /**
    * Takes care that a slash occurs only once.
    */
    function fixPath($path, $slash = NULL)
    {
        if(is_null($slash)){
            $slash = DIRECTORY_SEPARATOR;
        }
		$path = str_replace('/', $slash, $path);
		$path = str_replace('\\', $slash, $path);
		$path = str_replace($slash.'.'.$slash, $slash, $path);
  		$path = preg_replace('/\/{2,}|\\\{1,}/i', $slash, $path);
		$path = preg_replace('/\.$/', '', $path);
		return $path;
	}
    
    /**
    * Fixes wrong slashes (e.g. Linux slashes on Windows) and takes care
    * that a slash occurs only once.
    */
    function fixSlashes($path)
    {
        if(DIRECTORY_SEPARATOR == '/'){
            $wrong_separator = '\\';
        } else {
            $wrong_separator = '/';
        }
		$path = preg_replace('/\\'.DIRECTORY_SEPARATOR.'{2,}|\\'.$wrong_separator.'{1,}/i', DIRECTORY_SEPARATOR, $path);
        return $path;
    }
}
?>
Return current item: ZZ/OSS Installer