Index: branches/2.8.x/CHANGELOG
===================================================================
--- branches/2.8.x/CHANGELOG	(revision 1946)
+++ branches/2.8.x/CHANGELOG	(revision 1947)
@@ -11,6 +11,8 @@
 ! = Update/Change
 ===============================================================================
 
+03 Aug-2013 Build 1947 M.v.d.Decken(DarkViper)
++ added classes AccessFile and AccessFileHelper to /framework/
 03 Aug-2013 Build 1946 M.v.d.Decken(DarkViper)
 ! Droplet iParentPageIcon
 03 Aug-2013 Build 1945 M.v.d.Decken(DarkViper)
Index: branches/2.8.x/wb/admin/interface/version.php
===================================================================
--- branches/2.8.x/wb/admin/interface/version.php	(revision 1946)
+++ branches/2.8.x/wb/admin/interface/version.php	(revision 1947)
@@ -51,5 +51,5 @@
 
 // check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
 if(!defined('VERSION')) define('VERSION', '2.8.3');
-if(!defined('REVISION')) define('REVISION', '1946');
+if(!defined('REVISION')) define('REVISION', '1947');
 if(!defined('SP')) define('SP', '');
Index: branches/2.8.x/wb/framework/AccessFileHelper.php
===================================================================
--- branches/2.8.x/wb/framework/AccessFileHelper.php	(nonexistent)
+++ branches/2.8.x/wb/framework/AccessFileHelper.php	(revision 1947)
@@ -0,0 +1,141 @@
+<?php
+
+/**
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * AccessFileHelper.php
+ *
+ * @category     Core
+ * @package      Core_Routing
+ * @copyright    M.v.d.Decken <manuela@isteam.de>
+ * @author       M.v.d.Decken <manuela@isteam.de>
+ * @license      http://www.gnu.org/licenses/gpl.html   GPL License
+ * @version      0.0.1
+ * @revision     $Revision: $
+ * @link         $HeadURL: $
+ * @lastmodified $Date: $
+ * @since        File available since 01.08.2013
+ * @description  this class provides some helper methodes to handle access files
+ */
+
+class AccessFileHelper {
+
+/**
+ * do not delete start directory of deltree
+ */
+	const DEL_ROOT_PRESERVE = 0;
+/**
+ * delete start directory of deltree
+ */
+	const DEL_ROOT_DELETE   = 1;
+/**
+ * to store the last delTree log
+ */
+	static $aDelTreeLog = array();
+
+/**
+ * private constructor to deny instantiating
+ */
+	private function __construct() {
+		;
+	}
+/**
+ * Test if file is an access file
+ * @param       string $sFileName  qualified path/file
+ * @return      boolean
+ * @description test given file for typical accessfile signature
+ */
+	static public function isAccessFile($sFileName)
+	{
+		$bRetval = false;
+		if (($sFile = file_get_contents($sFileName)) !== false)
+		{
+			$sPattern = '/^\s*?<\?php.*?\$i?page_?id\s*=\s*[0-9]+;.*?(?:require|include)'
+					. '(?:_once)?\s*\(\s*\'.*?index\.php\'\s?\);/siU';
+			$bRetval = (bool) preg_match($sPattern, $sFile);
+			unset($sFile);
+		}
+		return $bRetval;
+	}
+/**
+ * Delete all contents of basedir, but not the basedir itself
+ * @param string  $sRootDir the content of which should be deleted
+ * @param integer $iMode    the mode can be set to self::DEL_ROOT_PRESERVE(default) or self::DEL_ROOT_DELETE
+ * @return boolean          false if a file or directory can't be deleted
+ */
+	static public function delTree($sRootDir, $iMode = self::DEL_ROOT_PRESERVE)
+	{
+		// check if root dir is inside the installation and is writeable
+		$oReg = WbAdaptor::getInstance();
+		self::$aDelTreeLog = array();
+		$bResult = true;
+		if (!is_writeable($sRootDir))
+		{
+			return false;
+			self::$aDelTreeLog[] = 'insufficient rights or directory not empty in : '.str_replace($oReg->AppPath, '', $sRootDir);
+		}
+		$oIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($sRootDir), RecursiveIteratorIterator::CHILD_FIRST);
+		foreach ($oIterator as $oPath)
+		{
+			$sPath = trim(str_replace('\\', '/', $oPath->__toString()), '/');
+			if ($oPath->isDir())
+			{
+				// proceed directories
+				if (!rmdir($sPath))
+				{
+					$bResult = false;
+					self::$aDelTreeLog[] = 'insufficient rights or directory not empty in : '.str_replace($oReg->AppPath, '', $sPath);
+				}else {
+					self::$aDelTreeLog[] = 'Directory successful removed : '.str_replace($oReg->AppPath, '', $sPath);
+				}
+			} elseif ($oPath->isFile())
+			{
+				// proceed files
+				if (!unlink($sPath))
+				{
+					$bResult = false;
+					self::$aDelTreeLog[] = 'insufficient rights or directory not empty in : '.str_replace($oReg->AppPath, '', $sPath);
+				}else {
+					self::$aDelTreeLog[] = 'File successful deleted : '.str_replace($oReg->AppPath, '', $sPath);
+				}
+			}
+		}
+		if (($iMode & self::DEL_ROOT_DELETE))
+		{
+			if ($bResult)
+			{ // if there was no error before
+				if (rmdir($sRootDir))
+				{
+					self::$aDelTreeLog[] = 'Directory successful removed : '.str_replace($oReg->AppPath, '', $sRootDir);
+					return $bResult;
+				}
+			}
+			self::$aDelTreeLog[] = 'insufficient rights or directory not empty in : '.str_replace($oReg->AppPath, '', $sRootDir);
+		}
+		return $bResult;
+	}
+/**
+ * returns the log of the last delTree request
+ * @return array
+ */
+	static function getDelTreeLog()
+	{
+		return self::$aDelTreeLog;
+	}
+
+} // end of class AccessFileHelper
Index: branches/2.8.x/wb/framework/AccessFile.php
===================================================================
--- branches/2.8.x/wb/framework/AccessFile.php	(nonexistent)
+++ branches/2.8.x/wb/framework/AccessFile.php	(revision 1947)
@@ -0,0 +1,388 @@
+<?php
+
+/**
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * AccessFile.php
+ *
+ * @category     Core
+ * @package      Core_Routing
+ * @copyright    M.v.d.Decken <manuela@isteam.de>
+ * @author       M.v.d.Decken <manuela@isteam.de>
+ * @license      http://www.gnu.org/licenses/gpl.html   GPL License
+ * @version      0.0.1
+ * @revision     $Revision: $
+ * @lastmodified $Date: $
+ * @since        File available since 17.01.2013
+ * @description  Create a single standard accessfile with additional var-entries
+ */
+class AccessFile {
+
+	/** int first private property */
+	protected $_oReg      = null;
+	protected $_sFileName = '';
+	protected $_aVars     = array();
+	protected $_aConsts   = array();
+	protected $_iErrorNo  = 0;
+
+	const VAR_STRING  = 'string';
+	const VAR_BOOL    = 'bool';
+	const VAR_BOOLEAN = 'bool';
+	const VAR_INT     = 'int';
+	const VAR_INTEGER = 'int';
+	const VAR_FLOAT   = 'float';
+
+	const FORCE_DELETE = true;
+
+	/**
+	 * Constructor
+	 * @param string full path and filename to the new access file
+	 * @param integer Id of the page or 0 for dummy files
+	 */
+	public function __construct($sFileName, $iPageId = 0)
+	{
+		$this->_oReg = WbAdaptor::getInstance();
+		$this->_sFileName = str_replace('\\', '/', $sFileName);
+		if (!preg_match('/^' . preg_quote($this->_oReg->AppPath, '/') . '/siU', $this->_sFileName)) {
+			throw new AccessFileInvalidFilePathException('tried to place file out of application path');
+		}
+		$this->_aVars['iPageId'] = intval($iPageId);
+	}
+	/**
+	 * Set Id of current page
+	 * @param integer PageId
+	 */
+	public function setPageId($iPageId)
+	{
+		$this->addVar('iPageId', $iPageId, $sType = self::VAR_INTEGER);
+	}
+
+	/**
+	 * Add new variable into the vars list
+	 * @param string name of the variable without leading '$'
+	 * @param mixed Value of the variable (Only scalar data (boolean, integer, float and string) are allowed)
+	 * @param string Type of the variable (use class constants to define)
+	 */
+	public function addVar($sName, $mValue, $sType = self::VAR_STRING)
+	{
+		$mValue = $this->_sanitizeValue($mValue, $sType);
+		$this->_aVars[$sName] = $mValue;
+	}
+
+	/**
+	 * Add new constant into the constants list
+	 * @param string name of the constant (upper case chars only)
+	 * @param mixed Value of the variable (Only scalar data (boolean, integer, float and string) are allowed)
+	 * @param string Type of the variable (use class constants to define)
+	 * @deprecated constants are not allowed from WB-version 2.9 and up
+	 */
+	public function addConst($sName, $mValue, $sType = self::VAR_STRING)
+	{
+		if (version_compare($this->_oReg->AppVersion, '2.9', '<'))
+		{
+			$mValue = $this->_sanitizeValue($mValue, $sType);
+			$this->_aConsts[strtoupper($sName)] = $mValue;
+		} else {
+			throw new AccessFileConstForbiddenException('define constants is not allowed from WB-version 2.9 and up');
+		}
+	}
+
+	/**
+	 * Write the accessfile
+	 * @throws AccessFileException
+	 */
+	public function write() 
+	{
+		// remove AppPath from File for use in error messages
+		$sTmp = str_replace($this->_oReg->AppPath, '', $this->_sFileName);
+		if (file_exists($this->_sFileName)) {
+			throw new AccessFileAlreadyExistsException('Accessfile already exists: * ' . $sTmp . ' *');
+		}
+
+		if (!$this->_aVars['iPageId']) {
+			// search for the parent pageID if current ID is 0
+			$this->_aVars['iPageId'] = $this->searchParentPageId($this->_sFileName);
+		}
+		$sIndexFile = $this->_buildPathToIndexFile($this->_sFileName);
+		$this->_createPath($this->_sFileName);
+		$sContent = $this->_buildFileContent($sIndexFile);
+		if (!file_put_contents($this->_sFileName, $sContent)) {
+			throw new AccessFileNotWriteableException('Unable to write file * ' . $sTmp . ' *');
+		}
+		if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { // Only chmod if os is not windows
+			chmod($this->_sFileName, $this->_oReg->OctalFileMode);
+		}
+	}
+
+	/**
+	 * Rename an existing Accessfile
+	 * @param string the new filename without path and without extension
+	 * @return boolean
+	 * @throws AccessFileInvalidFilenameException
+	 * @throws AccessFileAlreadyExistsException
+	 * @throws AccessFileAccessFileRenameException
+	 */
+	public function rename($sNewName)
+	{
+		// sanitize new filename
+		if (!preg_match('/[^\.\\\/]*/si', $sNewName)) {
+			throw new AccessFileInvalidFilenameException('invalid filename [' . $sNewName . ']');
+		}
+		// prepare old/new file-/dirname
+		$sOldFilename = $this->_sFileName;
+		$sOldSubDirname = dirname($sOldFilename) . '/';
+		$sPattern = '/^(' . preg_quote($sOldSubDirname, '/') . ')([^\/\.]+?)(\.[a-z0-9]+)$/siU';
+		$sNewFilename = preg_replace($sPattern, '\1' . $sNewName . '\3', $sOldFilename);
+		$sNewSubDirname = dirname($sNewFilename) . '/';
+		if (file_exists($sNewFilename) || file_exists($sNewSubDirname)) {
+			// check if new filename already exists
+			throw new AccessFileAlreadyExistsException('new file/dirname already exists [' . $sNewName . ']');
+		}
+		// try to rename a depending subdirectory
+		$bSubdirRenamed = false;
+		$bRetval = true;
+		if (file_exists($sOldSubDirname))
+		{
+			// old subdir exists but is it writeable?
+			if (($bRetval = is_writable($sOldSubDirname)))
+			{
+				if (rename($sOldSubDirname, $sNewSubDirname)) {
+					$bRetval = $bSubdirRenamed = true;
+				}
+			}
+		}
+		if (!$bRetval) {
+			// if old subdir exists and renaming failed
+			throw new AccessFileRenameException('unable to rename directory [' . $sOldSubDirname . ']');
+		}
+		if (($bRetval = is_writeable($this->_sFileName))) {
+			// try to rename accessfile
+			$bRetval = rename($sOldFilename, $sNewFilename);
+		}
+		if (!$bRetval)
+		{
+			if ($bSubdirRenamed) {
+				// on error undo renaming of subdir
+				rename($sNewSubDirname, $sOldSubDirname);
+			}
+			throw new AccessFileRenameException('unable to rename file [' . $sOldFilename . ']');
+		}
+	}
+
+	/**
+	 * Delete the actual Accessfile
+	 * @return boolean true if successfull
+	 * @throws AccessFileIsNoAccessfileException
+	 * @throws AccessFileNotWriteableException
+	 */
+	public function delete($bForceDelete = true)
+	{
+		$sFileName = $this->_sFileName;
+		if (!AccessFileHelper::isAccessFile($sFileName)) {
+			throw new AccessFileIsNoAccessfileException('requested file is NOT an accessfile');
+		}
+		if (file_exists($sFileName) && is_writeable($sFileName))
+		{
+			$sPattern = '/^(.*?)(\.[a-z0-9]+)$/siU';
+			$sDir = preg_replace($sPattern, '\1/', $sFileName);
+			if (is_writeable($sDir)) {
+				AccessFileHelper::delTree($sDir, AccessFileHelper::DEL_ROOT_DELETE);
+			}
+			unlink($sFileName);
+			$sFileName = '';
+		} else {
+			throw new AccessFileNotWriteableException('requested file not exists or permissions missing');
+		}
+	}
+
+	/**
+	 * getFilename
+	 * @return string path+name of the current accessfile
+	 */
+	public function getFileName()
+	{
+		return $this->_sFileName;
+	}
+
+	/**
+	 * getPageId
+	 * @return integer
+	 */
+	public function getPageId()
+	{
+		return (isset($this->_aVars['iPageId']) ? $this->_aVars['iPageId'] : 0);
+	}
+	/**
+	 * get number of the last occured error
+	 * @return int
+	 */
+	public function getError()
+	{
+		return $this->_iErrorNo;
+	}
+	/**
+	 * set number of error
+	 * @param type $iErrNo
+	 */
+	protected function _setError($iErrNo = self::ERR_NONE)
+	{
+		$this->_iErrorNo = $iErrNo;
+	}
+	/**
+	 * Create Path to Accessfile
+	 * @param string full path/name to new access file
+	 * @throws AccessFileNotWriteableException
+	 * @throws AccessFileInvalidStructureException
+	 */
+	protected function _createPath($sFilename)
+	{
+		$sFilename = str_replace($this->_oReg->AppPath . $this->_oReg->PagesDir, '', $sFilename);
+		$sPagesDir = $this->_oReg->AppPath . $this->_oReg->PagesDir;
+
+		if (($iSlashPosition = mb_strrpos($sFilename, '/')) !== false)
+		{
+			// if subdirs exists, then procceed extended check
+			$sExtension = preg_replace('/.*?(\.[a-z][a-z0-9]+)$/siU', '\1', $sFilename);
+			$sParentDir = mb_substr($sFilename, 0, $iSlashPosition);
+			if (file_exists($sPagesDir . $sParentDir))
+			{
+				if (!is_writable($sPagesDir . $sParentDir)) {
+					throw new AccessFileNotWriteableException('No write permissions for ' . $sPagesDir . $sParentDir);
+				}
+			} else
+			{
+				// if parentdir not exists
+				if (file_exists($sPagesDir . $sParentDir . $sExtension))
+				{
+					// but parentaccessfile exists, create parentdir and ok
+					$iOldUmask = umask(0);
+					$bRetval = mkdir($sPagesDir . $sParentDir, $this->_oReg->OctalDirMode);
+					umask($iOldUmask);
+				} else {
+					throw new AccessFileInvalidStructureException('invalid structure ' . $sFilename);
+				}
+				if (!$bRetval) {
+					throw new AccessFileNotWriteableException('Unable to create ' . $sPagesDir . $sParentDir);
+				}
+			}
+		}
+	}
+	/**
+	 * Sanitize value
+	 * @param mixed Value to sanitize
+	 * @param string Type of the variable (use class constants to define)
+	 * @return string printable value
+	 * @throws InvalidArgumentException
+	 */
+	protected function _sanitizeValue($mValue, $sType)
+	{
+		$mRetval = '';
+		switch ($sType)
+		{
+			case self::VAR_BOOLEAN:
+			case self::VAR_BOOL:
+				$mRetval = (filter_var(strtolower($mValue), FILTER_VALIDATE_BOOLEAN) ? '1' : '0');
+				break;
+			case self::VAR_INTEGER:
+			case self::VAR_INT:
+				if (filter_var($mValue, FILTER_VALIDATE_INT) === false) {
+					throw new InvalidArgumentException('value is not an integer');
+				}
+				$mRetval = (string) $mValue;
+				break;
+			case self::VAR_FLOAT:
+				if (filter_var($mValue, FILTER_VALIDATE_FLOAT) === false) {
+					throw new InvalidArgumentException('value is not a float');
+				}
+				$mRetval = (string) $mValue;
+				break;
+			default: // VAR_STRING
+				$mRetval = '\'' . (string) $mValue . '\'';
+				break;
+		}
+		return $mRetval;
+	}
+
+	/**
+	 * Calculate backsteps in directory
+	 * @param string accessfile
+	 */
+	protected function _buildPathToIndexFile($sFileName)
+	{
+		$iBackSteps = substr_count(str_replace($this->_oReg->AppPath, '', $sFileName), '/');
+		return str_repeat('../', $iBackSteps) . 'index.php';
+	}
+
+	/**
+	 * Build the content of the new accessfile
+	 * @param string $sIndexFile name and path to the wb/index.php file
+	 * @return string
+	 */
+	protected function _buildFileContent($sIndexFile)
+	{
+		$sFileContent
+				= '<?php' . "\n"
+				. '// *** This file is generated by ' . $this->_oReg->AppName
+				. ' Ver.' . $this->_oReg->AppVersion
+				. ($this->_oReg->AppServicePack != '' ? $this->_oReg->AppServicePack : '')
+				. ' Rev.' . $this->_oReg->AppRevision . "\n"
+				. '// *** Creation date: ' . date('c') . "\n"
+				. '// *** Do not modify this file manually' . "\n"
+				. '// *** This file will be rebuild from time to time!!' . "\n"
+				. '// *** Then all manual changes will get lost!! ' . "\n"
+				. '// *************************************************' . "\n";
+		foreach ($this->_aVars as $sKey => $sVar) {
+			$sFileContent .= "\t" . '$' . $sKey . ' = ' . $sVar . ';' . "\n";
+		}
+		foreach ($this->_aConsts as $sKey => $sVar) {
+			$sFileContent .= "\t" . 'define(\'' . $sKey . '\', ' . $sVar . '); // *deprecated command*' . "\n";
+		}
+		$sFileContent
+				.= "\t" . 'require(\'' . $sIndexFile . '\');' . "\n"
+				. '// *************************************************' . "\n"
+				. '// end of file' . "\n";
+
+		return $sFileContent;
+	}
+
+}
+
+// end of class AccessFile
+// //////////////////////////////////////////////////////////////////////////////////// //
+/**
+ * AccessFileException
+ *
+ * @category     WBCore
+ * @package      WBCore_Accessfiles
+ * @author       M.v.d.Decken <manuela@isteam.de>
+ * @copyright    M.v.d.Decken <manuela@isteam.de>
+ * @license      http://www.gnu.org/licenses/gpl.html   GPL License
+ * @version      2.9.0
+ * @revision     $Revision: 12 $
+ * @lastmodified $Date: 2012-12-29 21:39:37 +0100 (Sa, 29 Dez 2012) $
+ * @description  Exceptionhandler for the Accessfiles and depending classes
+ */
+
+class AccessFileException extends Exception { }
+class AccessFileConstForbiddenException extends AccessFileException { }
+class AccessFileInvalidFilePathException extends AccessFileException { }
+class AccessFileAlreadyExistsException extends AccessFileException { }
+class AccessFileNotWriteableException extends AccessFileException { }
+class AccessFileIsInvalidFilenameException extends AccessFileException { }
+class AccessFileIsNoAccessfileException extends AccessFileException { }
+class AccessFileInvalidStructureException extends AccessFileException { }
