Revision 2045
Added by Luisehahne almost 12 years ago
| branches/2.8.x/wb/admin/interface/version.php | ||
|---|---|---|
| 51 | 51 |
|
| 52 | 52 |
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled) |
| 53 | 53 |
if(!defined('VERSION')) define('VERSION', '2.8.4');
|
| 54 |
if(!defined('REVISION')) define('REVISION', '2044');
|
|
| 54 |
if(!defined('REVISION')) define('REVISION', '2045');
|
|
| 55 | 55 |
if(!defined('SP')) define('SP', '');
|
| branches/2.8.x/wb/framework/AccessFileHelper.php | ||
|---|---|---|
| 22 | 22 |
* |
| 23 | 23 |
* @category Core |
| 24 | 24 |
* @package Core_Routing |
| 25 |
* @copyright M.v.d.Decken <manuela@isteam.de> |
|
| 26 |
* @author M.v.d.Decken <manuela@isteam.de> |
|
| 25 |
* @subpackage Accessfiles |
|
| 26 |
* @copyright Manuela v.d.Decken <manuela@isteam.de> |
|
| 27 |
* @author Manuela v.d.Decken <manuela@isteam.de> |
|
| 27 | 28 |
* @license http://www.gnu.org/licenses/gpl.html GPL License |
| 28 | 29 |
* @version 0.0.1 |
| 29 | 30 |
* @revision $Revision: $ |
| ... | ... | |
| 32 | 33 |
* @since File available since 01.08.2013 |
| 33 | 34 |
* @description this class provides some helper methodes to handle access files |
| 34 | 35 |
*/ |
| 35 |
|
|
| 36 |
if (class_exists('AccesFile')) {;}
|
|
| 36 | 37 |
class AccessFileHelper {
|
| 37 | 38 |
|
| 38 | 39 |
/** |
| ... | ... | |
| 70 | 71 |
*/ |
| 71 | 72 |
static public function isAccessFile($sFileName) |
| 72 | 73 |
{
|
| 74 |
if (!is_readable($sFileName)) { throw new AccessFileInvalidFilePathException('invalid filename ['.$sFileName.']');
|
|
| 73 | 75 |
$bRetval = false; |
| 74 |
if (($sFile = file_get_contents($sFileName)) !== false) |
|
| 75 |
{
|
|
| 76 |
if (($sFile = file_get_contents($sFileName)) !== false) {
|
|
| 76 | 77 |
$sPattern = '/^\s*?<\?php.*?\$i?page_?id\s*=\s*[0-9]+;.*?(?:require|include)' |
| 77 |
. '(?:_once)?\s*\(\s*\'.*?index\.php\'\s?\);/siU';
|
|
| 78 |
. '(?:_once)?\s*\(\s*\'.*?index\.php\'\s?\);/siU';
|
|
| 78 | 79 |
$bRetval = (bool) preg_match($sPattern, $sFile); |
| 79 | 80 |
unset($sFile); |
| 80 | 81 |
} |
| 81 | 82 |
return $bRetval; |
| 82 |
} |
|
| 83 |
} |
|
| 84 |
} |
|
| 83 | 85 |
/** |
| 84 | 86 |
* Delete all contents of basedir, but not the basedir itself |
| 85 | 87 |
* @param string $sRootDir the content of which should be deleted |
| ... | ... | |
| 92 | 94 |
$oReg = WbAdaptor::getInstance(); |
| 93 | 95 |
self::$aDelTreeLog = array(); |
| 94 | 96 |
$bResult = true; |
| 95 |
if (!is_writeable($sRootDir)) |
|
| 96 |
{
|
|
| 97 |
if (!is_writeable($sRootDir)) {
|
|
| 97 | 98 |
self::$aDelTreeLog[] = 'insufficient rights or directory not empty in : '.str_replace($oReg->AppPath, '', $sRootDir); |
| 98 | 99 |
return false; |
| 99 | 100 |
} |
| 100 | 101 |
$oIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($sRootDir), RecursiveIteratorIterator::CHILD_FIRST); |
| 101 |
foreach ($oIterator as $oPath) |
|
| 102 |
{
|
|
| 102 |
foreach ($oIterator as $oPath) {
|
|
| 103 | 103 |
$sPath = rtrim(str_replace('\\', '/', $oPath->__toString()), '/');
|
| 104 |
if ($oPath->isDir() && !preg_match('/\.$/s', $sPath))
|
|
| 105 |
{
|
|
| 104 |
if ($oPath->isDir() && !preg_match('/\.$/s', $sPath)) {
|
|
| 106 | 105 |
// proceed directories |
| 107 |
if (!rmdir($sPath)) |
|
| 108 |
{
|
|
| 106 |
if (!rmdir($sPath)) {
|
|
| 109 | 107 |
$bResult = false; |
| 110 | 108 |
self::$aDelTreeLog[] = 'insufficient rights or directory not empty in : '.str_replace($oReg->AppPath, '', $sPath); |
| 111 |
}else {
|
|
| 109 |
} else {
|
|
| 112 | 110 |
self::$aDelTreeLog[] = 'Directory successful removed : '.str_replace($oReg->AppPath, '', $sPath); |
| 113 | 111 |
} |
| 114 |
} elseif ($oPath->isFile()) |
|
| 115 |
{
|
|
| 112 |
} elseif ($oPath->isFile()) {
|
|
| 116 | 113 |
// proceed files |
| 117 |
if (!unlink($sPath)) |
|
| 118 |
{
|
|
| 114 |
if (!unlink($sPath)) {
|
|
| 119 | 115 |
$bResult = false; |
| 120 | 116 |
self::$aDelTreeLog[] = 'insufficient rights or directory not empty in : '.str_replace($oReg->AppPath, '', $sPath); |
| 121 |
}else {
|
|
| 117 |
} else {
|
|
| 122 | 118 |
self::$aDelTreeLog[] = 'File successful deleted : '.str_replace($oReg->AppPath, '', $sPath); |
| 123 | 119 |
} |
| 124 | 120 |
} |
| 125 | 121 |
} |
| 126 |
if (($iMode & self::DEL_ROOT_DELETE)) |
|
| 127 |
{
|
|
| 128 |
if ($bResult) |
|
| 129 |
{ // if there was no error before
|
|
| 130 |
if (rmdir($sRootDir)) |
|
| 131 |
{
|
|
| 122 |
if (($iMode & self::DEL_ROOT_DELETE)) {
|
|
| 123 |
if ($bResult) { // if there was no error before
|
|
| 124 |
if (rmdir($sRootDir)) {
|
|
| 132 | 125 |
self::$aDelTreeLog[] = 'Directory successful removed : '.str_replace($oReg->AppPath, '', $sRootDir); |
| 133 | 126 |
return $bResult; |
| 134 | 127 |
} |
| ... | ... | |
| 142 | 135 |
* @param bool $bClearLog TRUE clears the log after request, FALSE preserve the log |
| 143 | 136 |
* @return array |
| 144 | 137 |
*/ |
| 145 |
static function getDelTreeLog($bClearLog = self::LOG_CLEAR) |
|
| 138 |
static public function getDelTreeLog($bClearLog = self::LOG_CLEAR)
|
|
| 146 | 139 |
{
|
| 147 | 140 |
$aRetval = self::$aDelTreeLog; |
| 148 | 141 |
if($bClearLog) { self::$aDelTreeLog = array(); }
|
| 149 | 142 |
return $aRetval; |
| 150 | 143 |
} |
| 151 | 144 |
|
| 145 |
/* *** following methods still are in developing right now! Do not use it! ************ */ |
|
| 146 |
|
|
| 147 |
/** |
|
| 148 |
* isPathInsideApplication |
|
| 149 |
* @param string $sRootPath full base path<br /> |
|
| 150 |
* example1-a: '/www/htdocs/subdir/' |
|
| 151 |
* example2-a: 'c://www/htdocs/subdir/' |
|
| 152 |
* example3-a: 'http://user:pass@isteam.de:123/www/htdocs/subdir/' |
|
| 153 |
* @param string $sFullPath full path to test<br /> |
|
| 154 |
* example1-b: '/www/htdocs/subdir/targetdir/../testfile.php' |
|
| 155 |
* example2-b: 'c://www/htdocs/subdir/targetdir/../testfile.php' |
|
| 156 |
* example3-b: 'http://user:pass@isteam.de:123/www/htdocs/subdir/targetdir/../testfile.php' |
|
| 157 |
* @return type |
|
| 158 |
*/ |
|
| 159 |
static public function isRootPartOfPath($sRootPath, $sFullPath) |
|
| 160 |
{
|
|
| 161 |
$sRootPath = self::getRealPath($sRootPath); |
|
| 162 |
$sFullPath = self::getRealPath($sFullPath); |
|
| 163 |
$sRetval = (preg_match('/^'.preg_quote($sRootPath, '/').'/', $sFullPath) ? $sFullPath : null );
|
|
| 164 |
return $sRetval;; |
|
| 165 |
} |
|
| 166 |
|
|
| 167 |
static public function getRealPath($sPath) |
|
| 168 |
{
|
|
| 169 |
$iCount = 0; |
|
| 170 |
$aResultPath = array(); |
|
| 171 |
$sPath = str_replace(array('\\', '/./'), array('/', '/'), $sPath);
|
|
| 172 |
if(preg_match('/^\/?\.\//', $sPath)) {
|
|
| 173 |
$sPath = str_replace('\\', '/', getcwd()).'/'.preg_replace('/^\/?\.\//', '', $sPath);
|
|
| 174 |
} |
|
| 175 |
|
|
| 176 |
$sPattern = '/((?:^[a-z]?\:\/+)|(?:^.*?\:\/\/.*?\/)|(?:^\/+))[^\/].*$/is'; |
|
| 177 |
// extract host/root - part from path save and then remove it from path |
|
| 178 |
$sPrefix = preg_replace($sPattern, '\1', $sPath); |
|
| 179 |
$sPath = preg_replace('/^'.preg_quote($sPrefix, '/').'/', '', $sPath);
|
|
| 180 |
// replace any tripple or more dots by doubble dots and split the path at '/' into an array. |
|
| 181 |
// save number of replaced .. in $iCount and add somme buffer elements |
|
| 182 |
$aTestPath = array_merge(($iCount ? array_fill(0, $iCount * 2, '###') : array()), |
|
| 183 |
explode('/', preg_replace(array('/\.{2,}/s', '/./'), array('..', '/'), $sPath, -1, $iCount))
|
|
| 184 |
); |
|
| 185 |
foreach ($aTestPath as $sPart) {
|
|
| 186 |
switch ($sPart) {
|
|
| 187 |
case '.': // skip part |
|
| 188 |
continue; |
|
| 189 |
break; |
|
| 190 |
case '..': // step back |
|
| 191 |
array_pop($aResultPath); |
|
| 192 |
break; |
|
| 193 |
default: // take part |
|
| 194 |
$aResultPath[] = $sPart; |
|
| 195 |
break; |
|
| 196 |
} |
|
| 197 |
} |
|
| 198 |
while($aResultPath[0] == '###') {
|
|
| 199 |
array_shift($aResultPath); |
|
| 200 |
} |
|
| 201 |
$sResultPath = $sPrefix.implode('/', $aResultPath);
|
|
| 202 |
return $sResultPath; |
|
| 203 |
} |
|
| 204 |
|
|
| 205 |
|
|
| 152 | 206 |
} // end of class AccessFileHelper |
| branches/2.8.x/wb/framework/AccessFile.php | ||
|---|---|---|
| 22 | 22 |
* |
| 23 | 23 |
* @category Core |
| 24 | 24 |
* @package Core_Routing |
| 25 |
* @copyright M.v.d.Decken <manuela@isteam.de> |
|
| 26 |
* @author M.v.d.Decken <manuela@isteam.de> |
|
| 25 |
* @subpackage Accessfiles |
|
| 26 |
* @copyright Manuela v.d.Decken <manuela@isteam.de> |
|
| 27 |
* @author Manuela v.d.Decken <manuela@isteam.de> |
|
| 27 | 28 |
* @license http://www.gnu.org/licenses/gpl.html GPL License |
| 28 | 29 |
* @version 0.0.1 |
| 29 | 30 |
* @revision $Revision: $ |
| 30 | 31 |
* @lastmodified $Date: $ |
| 31 | 32 |
* @since File available since 17.01.2013 |
| 32 |
* @description Create a single standard accessfile with additional var-entries
|
|
| 33 |
* @description Single standard accessfile with additional var-entries
|
|
| 33 | 34 |
*/ |
| 34 | 35 |
class AccessFile {
|
| 35 | 36 |
|
| 36 | 37 |
/** int first private property */ |
| 37 |
protected $_oReg = null; |
|
| 38 |
protected $_sFileName = ''; |
|
| 39 |
protected $_aVars = array(); |
|
| 40 |
protected $_aConsts = array(); |
|
| 41 |
protected $_iErrorNo = 0; |
|
| 38 |
protected $oReg = null; |
|
| 39 |
protected $sAccessFilesRoot = ''; // basedir of the current AccessFile structure |
|
| 40 |
protected $sFileName = ''; // filename and path from AccessFilesRoot (without extension) |
|
| 41 |
protected $sFullFileName = ''; // full path and filename (without extension) |
|
| 42 |
protected $sFileExtension = '.php'; // extension for all accessfiles (default: '.php') |
|
| 43 |
protected $aVars = array(); // variables in accessfile |
|
| 44 |
protected $aConsts = array(); // constants in accessfile |
|
| 45 |
protected $iErrorNo = 0; |
|
| 42 | 46 |
|
| 43 | 47 |
const VAR_STRING = 'string'; |
| 44 | 48 |
const VAR_BOOL = 'bool'; |
| ... | ... | |
| 51 | 55 |
|
| 52 | 56 |
/** |
| 53 | 57 |
* Constructor |
| 54 |
* @param string full path and filename to the new access file |
|
| 55 |
* @param integer Id of the page or 0 for dummy files |
|
| 58 |
* @param string $sAccessFilesRoot full path to the base directory of accessfiles-tree |
|
| 59 |
* @param string $sFileName subdirectory and filename of the new access file from AccessFilesRoot<br /> |
|
| 60 |
* (indirect addressing (./ | ../) is not allowed here!!) |
|
| 61 |
* @param integer $iPageId (default: 0) Id of the page or 0 for dummy files |
|
| 62 |
* @throws AccessFileInvalidFilePathException |
|
| 56 | 63 |
*/ |
| 57 |
public function __construct($sFileName, $iPageId = 0) |
|
| 64 |
public function __construct($sAccessFilesRoot, $sFileName, $iPageId = 0)
|
|
| 58 | 65 |
{
|
| 59 |
$this->_oReg = WbAdaptor::getInstance(); |
|
| 60 |
$this->_sFileName = str_replace('\\', '/', $sFileName);
|
|
| 61 |
if (!preg_match('/^' . preg_quote($this->_oReg->AppPath, '/') . '/siU', $this->_sFileName)) {
|
|
| 62 |
throw new AccessFileInvalidFilePathException('tried to place file out of application path');
|
|
| 66 |
$this->oReg = WbAdaptor::getInstance(); |
|
| 67 |
$this->sFileExtension = $this->oReg->PageExtension; |
|
| 68 |
// sanitize AccessFilesRoot |
|
| 69 |
if (($sX = realpath($sAccessFilesRoot)) == false) {
|
|
| 70 |
throw new AccessFileInvalidFilePathException('invalid path for AccessFilesRoot given [ '.$sAccessFilesRoot.' ]');
|
|
| 63 | 71 |
} |
| 64 |
$this->_aVars['iPageId'] = intval($iPageId); |
|
| 72 |
$sAccessFilesRoot = rtrim(str_replace('\\', '/', $sX), '/').'/';
|
|
| 73 |
// check location of AccessFilesRoot |
|
| 74 |
if (!preg_match('/^' . preg_quote($this->oReg->AppPath, '/') . '/siU', $sAccessFilesRoot)) {
|
|
| 75 |
throw new AccessFileInvalidFilePathException('tried to place AccessFilesRoot out of application path [ '.$sAccessFilesRoot.' ]');
|
|
| 76 |
} |
|
| 77 |
$this->sAccessFilesRoot = $sAccessFilesRoot; |
|
| 78 |
// sanitize Filename |
|
| 79 |
$sFileName = preg_replace('/'.preg_quote($this->sFileExtension, '/').'$/', '', $sFileName);
|
|
| 80 |
$this->sFileName = ltrim(rtrim(trim(str_replace('\\', '/', $sFileName)), '/'), './');
|
|
| 81 |
if (preg_match('/\.\.+\//', $this->sFileName)) {
|
|
| 82 |
throw new AccessFileInvalidFilePathException('relative path (./ or ../) is not allowed in Filename!! [ '.$this->sFileName.' ]');
|
|
| 83 |
} |
|
| 84 |
$this->sFullFileName = $this->sAccessFilesRoot . $this->sFileName; |
|
| 85 |
$this->aVars['iPageId'] = intval($iPageId); |
|
| 86 |
|
|
| 65 | 87 |
} |
| 66 | 88 |
/** |
| 67 | 89 |
* Set Id of current page |
| ... | ... | |
| 80 | 102 |
*/ |
| 81 | 103 |
public function addVar($sName, $mValue, $sType = self::VAR_STRING) |
| 82 | 104 |
{
|
| 83 |
$mValue = $this->_sanitizeValue($mValue, $sType);
|
|
| 84 |
$this->_aVars[$sName] = $mValue;
|
|
| 105 |
$mValue = $this->sanitizeValue($mValue, $sType); |
|
| 106 |
$this->aVars[$sName] = $mValue; |
|
| 85 | 107 |
} |
| 86 | 108 |
|
| 87 | 109 |
/** |
| ... | ... | |
| 89 | 111 |
* @param string name of the constant (upper case chars only) |
| 90 | 112 |
* @param mixed Value of the variable (Only scalar data (boolean, integer, float and string) are allowed) |
| 91 | 113 |
* @param string Type of the variable (use class constants to define) |
| 114 |
* @throws AccessFileConstForbiddenException |
|
| 92 | 115 |
* @deprecated constants are not allowed from WB-version 2.9 and up |
| 93 | 116 |
*/ |
| 94 | 117 |
public function addConst($sName, $mValue, $sType = self::VAR_STRING) |
| 95 | 118 |
{
|
| 96 |
if (version_compare($this->_oReg->AppVersion, '2.9', '<'))
|
|
| 119 |
if (version_compare($this->oReg->AppVersion, '2.9', '<')) |
|
| 97 | 120 |
{
|
| 98 |
$mValue = $this->_sanitizeValue($mValue, $sType);
|
|
| 99 |
$this->_aConsts[strtoupper($sName)] = $mValue;
|
|
| 121 |
$mValue = $this->sanitizeValue($mValue, $sType); |
|
| 122 |
$this->aConsts[strtoupper($sName)] = $mValue; |
|
| 100 | 123 |
} else {
|
| 101 | 124 |
throw new AccessFileConstForbiddenException('define constants is not allowed from WB-version 2.9 and up');
|
| 102 | 125 |
} |
| ... | ... | |
| 104 | 127 |
|
| 105 | 128 |
/** |
| 106 | 129 |
* Write the accessfile |
| 107 |
* @throws AccessFileException |
|
| 130 |
* @throws AccessFileWriteableException
|
|
| 108 | 131 |
*/ |
| 109 | 132 |
public function write() |
| 110 | 133 |
{
|
| 111 |
// remove AppPath from File for use in error messages |
|
| 112 |
$sTmp = str_replace($this->_oReg->AppPath, '', $this->_sFileName); |
|
| 113 |
if (file_exists($this->_sFileName)) {
|
|
| 114 |
throw new AccessFileAlreadyExistsException('Accessfile already exists: * ' . $sTmp . ' *');
|
|
| 134 |
// full path and filename |
|
| 135 |
$sFileName = $this->sFullFileName.$this->sFileExtension; |
|
| 136 |
// remove AppPath from File for use in error messages |
|
| 137 |
$sDisplayFilename = str_replace($this->oReg->AppPath, '', $sFileName); |
|
| 138 |
// do not allow writing if PageId is missing! |
|
| 139 |
if (!$this->aVars['iPageId']) {
|
|
| 140 |
throw new AccessFileWriteableException('Missing PageId for file [' . $sDisplayFilename . ']');
|
|
| 115 | 141 |
} |
| 116 |
|
|
| 117 |
if (!$this->_aVars['iPageId']) {
|
|
| 118 |
// search for the parent pageID if current ID is 0 |
|
| 119 |
$this->_aVars['iPageId'] = $this->searchParentPageId($this->_sFileName); |
|
| 142 |
// build the content for the access file |
|
| 143 |
$sContent = $this->buildFileContent($this->buildPathToIndexFile($sFileName)); |
|
| 144 |
// create path if file does not already exists |
|
| 145 |
if (!file_exists($sFileName)) {
|
|
| 146 |
$this->createPath($sFileName); |
|
| 120 | 147 |
} |
| 121 |
$sIndexFile = $this->_buildPathToIndexFile($this->_sFileName); |
|
| 122 |
$this->_createPath($this->_sFileName); |
|
| 123 |
$sContent = $this->_buildFileContent($sIndexFile); |
|
| 124 |
if (!file_put_contents($this->_sFileName, $sContent)) {
|
|
| 125 |
throw new AccessFileNotWriteableException('Unable to write file * ' . $sTmp . ' *');
|
|
| 148 |
// create new file or overwrite existing one |
|
| 149 |
if (!file_put_contents($sFileName, $sContent)) {
|
|
| 150 |
throw new AccessFileWriteableException('Unable to write file [' . $sDisplayFilename . ']');
|
|
| 126 | 151 |
} |
| 127 |
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { // Only chmod if os is not windows
|
|
| 128 |
chmod($this->_sFileName, $this->_oReg->OctalFileMode); |
|
| 152 |
// do chmod if os is not windows |
|
| 153 |
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
|
|
| 154 |
chmod($sFileName, $this->oReg->OctalFileMode); |
|
| 129 | 155 |
} |
| 130 | 156 |
} |
| 131 | 157 |
|
| 158 |
/** |
|
| 159 |
* searchParentPageId |
|
| 160 |
* @param string $sAccessFilesRoot |
|
| 161 |
* @param string $sFullFilePath |
|
| 162 |
* @return int found page-id |
|
| 163 |
* @description find first valid accessfile backwards in the parent line<br /> |
|
| 164 |
* or the start page if no parent is found. |
|
| 165 |
*/ |
|
| 166 |
protected function searchParentPageId($sAccessFilesRoot, $sFullFilePath) |
|
| 167 |
{
|
|
| 168 |
|
|
| 169 |
|
|
| 170 |
return $iPageId; |
|
| 171 |
} |
|
| 132 | 172 |
/** |
| 133 | 173 |
* Rename an existing Accessfile |
| 134 | 174 |
* @param string $sNewName the new filename without path and without extension |
| 135 | 175 |
* @return boolean |
| 136 |
* @throws AccessFileInvalidFilenameException |
|
| 137 |
* @throws AccessFileAlreadyExistsException |
|
| 138 | 176 |
* @throws AccessFileAccessFileRenameException |
| 139 | 177 |
*/ |
| 140 | 178 |
public function rename($sNewName) |
| 141 | 179 |
{
|
| 142 |
// sanitize new filename |
|
| 143 |
if (!preg_match('/[^\.\\ \/]*/si', $sNewName)) {
|
|
| 144 |
throw new AccessFileInvalidFilenameException('invalid filename [' . str_replace($this->_oReg->AppPath, '', $sNewName) . ']');
|
|
| 180 |
// validate and sanitize new filename |
|
| 181 |
$sPattern = '/(^'.preg_quote($this->sAccessFilesRoot, '/').'|^'.preg_quote($this->oReg->AppPath, '/') |
|
| 182 |
. ')?([^\/]*?)(?:'.preg_quote($this->sFileExtension, '/').')?$/s'; |
|
| 183 |
if (!preg_match($sPattern, $sNewName, $aMatches)) {
|
|
| 184 |
// sorry, but the given filename is not valid! |
|
| 185 |
throw new AccessFileRenameException('invalid filename [' . str_replace($this->oReg->AppPath, '', $sNewName) . ']');
|
|
| 145 | 186 |
} |
| 146 |
// prepare old/new file-/dirname
|
|
| 147 |
$sOldFilename = $this->_sFileName;
|
|
| 148 |
$sOldSubDirname = dirname($sOldFilename) . '/';
|
|
| 149 |
$sPattern = '/^(' . preg_quote($sOldSubDirname, '/') . ')([^\/\.]+?)(\.[a-z0-9]+)$/siU';
|
|
| 150 |
$sNewFilename = preg_replace($sPattern, '\1' . $sNewName . '\3', $sOldFilename);
|
|
| 151 |
$sNewSubDirname = dirname($sNewFilename) . '/'; |
|
| 152 |
if (file_exists($sNewFilename) || file_exists($sNewSubDirname)) {
|
|
| 153 |
// if new filename or directory already exists
|
|
| 154 |
throw new AccessFileAlreadyExistsException('new file/dirname already exists [' . str_replace($this->_oReg->AppPath, '', $sNewName) . ']');
|
|
| 187 |
$sOldFileName = $this->sFullFileName;
|
|
| 188 |
// $aMatches[sizeof($aMatches)-1] contains the new filename without extension only
|
|
| 189 |
$sNewFileName = preg_replace('/(^.*?)[^\/]*$/', '\1'.$aMatches[sizeof($aMatches)-1], $sOldFileName);
|
|
| 190 |
$sDisplayOldFileName = str_replace($this->oReg->AppPath, '', $sOldFileName);
|
|
| 191 |
$sDisplayNewFileName = str_replace($this->oReg->AppPath, '', $sNewFileName);
|
|
| 192 |
|
|
| 193 |
if (file_exists($sNewFileName.$this->sFileExtension) || file_exists($sNewFileName.'/')) {
|
|
| 194 |
// if new filename or directory already exists |
|
| 195 |
throw new AccessFileRenameException('new file or new dirname already exists ['.$sDisplayNewFileName.'{'.$this->sFileExtension.'}]');
|
|
| 155 | 196 |
} |
| 156 |
if(!is_writeable($sOldFilename)) {
|
|
| 157 |
throw new AccessFileRenameException('unable to rename file or file not exists [' . str_replace($this->_oReg->AppPath, '', $sOldFilename) . ']');
|
|
| 197 |
if (!is_writeable($sOldFileName.$this->sFileExtension)) {
|
|
| 198 |
// old file is not writable an can not be renamed |
|
| 199 |
throw new AccessFileRenameException('file not exists or file is readonly ['.$sDisplayOldFileName.$this->sFileExtension.']');
|
|
| 158 | 200 |
} |
| 159 | 201 |
$bSubdirRenamed = false; // set default value |
| 160 |
if(file_exists($sOldSubDirname)) |
|
| 161 |
{ //
|
|
| 162 |
if(is_writeable($sOldSubDirname)) |
|
| 163 |
{
|
|
| 164 |
if(!( $bSubdirRenamed = rename($sOldSubDirname, $sNewSubDirname))) {
|
|
| 165 |
throw new AccessFileRenameException('unable to rename directory [' . str_replace($this->_oReg->AppPath, '', $sOldSubDirname) . ']');
|
|
| 202 |
if (file_exists($sOldFileName.'/')) { //
|
|
| 203 |
if (is_writeable($sOldFileName.'/')) {
|
|
| 204 |
if (!( $bSubdirRenamed = rename($sOldFileName.'/', $sOldFileName.'/'))) {
|
|
| 205 |
throw new AccessFileRenameException('unable to rename directory ['.$sDisplayOldFileName.'/] to ['.$sDisplayNewFileName.'/]');
|
|
| 166 | 206 |
} |
| 167 | 207 |
} else {
|
| 168 |
throw new AccessFileRenameException('directory is not writeable [' . str_replace($this->_oReg->AppPath, '', $sOldSubDirname) . ']');
|
|
| 208 |
throw new AccessFileRenameException('directory is not writeable ['.$sDisplayOldFileName.'/]');
|
|
| 169 | 209 |
} |
| 170 | 210 |
} |
| 171 | 211 |
// try to rename accessfile |
| 172 |
if(!rename($sOldFilename, $sNewFilename)) {
|
|
| 173 |
if($bSubdirRenamed) { rename($sNewSubDirname, $sOldSubDirname); }
|
|
| 174 |
throw new AccessFileRenameException('unable to rename file [' . str_replace($this->_oReg->AppPath, '', $sOldFilename) . ']');
|
|
| 212 |
if (!rename($sOldFileName.$this->sFileExtension, $sNewFileName.$this->sFileExtension)) {
|
|
| 213 |
if ($bSubdirRenamed) { rename($sNewFileName.'/', $sOldFileName.'/'); }
|
|
| 214 |
$sMsg = 'unable to rename file ['.$sDisplayOldFileName.$this->sFileExtension |
|
| 215 |
. '] to ['.$sDisplayOldFileName.$this->sFileExtension.']'; |
|
| 216 |
throw new AccessFileRenameException($sMsg); |
|
| 175 | 217 |
} |
| 176 | 218 |
return true; |
| 177 | 219 |
} |
| ... | ... | |
| 180 | 222 |
* Delete the actual Accessfile |
| 181 | 223 |
* @return boolean true if successfull |
| 182 | 224 |
* @throws AccessFileIsNoAccessfileException |
| 183 |
* @throws AccessFileNotWriteableException
|
|
| 225 |
* @throws AccessFileWriteableException |
|
| 184 | 226 |
*/ |
| 185 | 227 |
public function delete($bForceDelete = true) |
| 186 | 228 |
{
|
| 187 |
$sFileName = $this->_sFileName; |
|
| 229 |
$sFileName = $this->sFullFileName.$this->sFileExtension; |
|
| 230 |
|
|
| 188 | 231 |
if (!AccessFileHelper::isAccessFile($sFileName)) {
|
| 189 | 232 |
throw new AccessFileIsNoAccessfileException('requested file is NOT an accessfile');
|
| 190 | 233 |
} |
| 191 | 234 |
if (file_exists($sFileName) && is_writeable($sFileName)) |
| 192 | 235 |
{
|
| 193 |
$sPattern = '/^(.*?)(\.[a-z0-9]+)$/siU'; |
|
| 194 |
$sDir = preg_replace($sPattern, '\1/', $sFileName); |
|
| 195 |
if (is_writeable($sDir)) {
|
|
| 196 |
AccessFileHelper::delTree($sDir, AccessFileHelper::DEL_ROOT_DELETE); |
|
| 236 |
if (is_writeable($this->sFullFileName)) {
|
|
| 237 |
AccessFileHelper::delTree($this->sFullFileName, AccessFileHelper::DEL_ROOT_DELETE); |
|
| 197 | 238 |
} |
| 198 | 239 |
unlink($sFileName); |
| 199 | 240 |
$sFileName = ''; |
| 200 | 241 |
} else {
|
| 201 |
throw new AccessFileNotWriteableException('requested file not exists or permissions missing');
|
|
| 242 |
throw new AccessFileWriteableException('requested file not exists or permissions missing');
|
|
| 202 | 243 |
} |
| 203 | 244 |
} |
| 204 | 245 |
|
| ... | ... | |
| 208 | 249 |
*/ |
| 209 | 250 |
public function getFileName() |
| 210 | 251 |
{
|
| 211 |
return $this->_sFileName;
|
|
| 252 |
return $this->sFullFileName.$this->sFileExtension;
|
|
| 212 | 253 |
} |
| 213 | 254 |
|
| 214 | 255 |
/** |
| ... | ... | |
| 217 | 258 |
*/ |
| 218 | 259 |
public function getPageId() |
| 219 | 260 |
{
|
| 220 |
return (isset($this->_aVars['iPageId']) ? $this->_aVars['iPageId'] : 0);
|
|
| 261 |
return (isset($this->aVars['iPageId']) ? $this->aVars['iPageId'] : 0);
|
|
| 221 | 262 |
} |
| 222 | 263 |
/** |
| 223 | 264 |
* get number of the last occured error |
| ... | ... | |
| 225 | 266 |
*/ |
| 226 | 267 |
public function getError() |
| 227 | 268 |
{
|
| 228 |
return $this->_iErrorNo;
|
|
| 269 |
return $this->iErrorNo; |
|
| 229 | 270 |
} |
| 230 | 271 |
/** |
| 231 | 272 |
* set number of error |
| 232 | 273 |
* @param type $iErrNo |
| 233 | 274 |
*/ |
| 234 |
protected function _setError($iErrNo = self::ERR_NONE)
|
|
| 275 |
protected function setError($iErrNo = self::ERR_NONE) |
|
| 235 | 276 |
{
|
| 236 |
$this->_iErrorNo = $iErrNo;
|
|
| 277 |
$this->iErrorNo = $iErrNo; |
|
| 237 | 278 |
} |
| 238 | 279 |
/** |
| 239 | 280 |
* Create Path to Accessfile |
| 240 | 281 |
* @param string full path/name to new access file |
| 241 |
* @throws AccessFileNotWriteableException
|
|
| 282 |
* @throws AccessFileWriteableException |
|
| 242 | 283 |
* @throws AccessFileInvalidStructureException |
| 243 | 284 |
*/ |
| 244 |
protected function _createPath($sFilename)
|
|
| 285 |
protected function createPath($sFilename) |
|
| 245 | 286 |
{
|
| 246 |
$sFilename = str_replace($this->_oReg->AppPath . $this->_oReg->PagesDir, '', $sFilename); |
|
| 247 |
$sPagesDir = $this->_oReg->AppPath . $this->_oReg->PagesDir; |
|
| 248 |
|
|
| 249 |
if (($iSlashPosition = mb_strrpos($sFilename, '/')) !== false) |
|
| 250 |
{
|
|
| 287 |
$sFilename = str_replace($this->sAccessFilesRoot, '', $sFilename); |
|
| 288 |
$sPagesDir = $this->sAccessFilesRoot; |
|
| 289 |
if (($iSlashPosition = mb_strrpos($sFilename, '/')) !== false) {
|
|
| 251 | 290 |
// if subdirs exists, then procceed extended check |
| 252 | 291 |
$sExtension = preg_replace('/.*?(\.[a-z][a-z0-9]+)$/siU', '\1', $sFilename);
|
| 253 | 292 |
$sParentDir = mb_substr($sFilename, 0, $iSlashPosition); |
| 254 |
if (file_exists($sPagesDir . $sParentDir)) |
|
| 255 |
{
|
|
| 293 |
if (file_exists($sPagesDir . $sParentDir)) {
|
|
| 256 | 294 |
if (!is_writable($sPagesDir . $sParentDir)) {
|
| 257 |
throw new AccessFileNotWriteableException('No write permissions for ' . $sPagesDir . $sParentDir);
|
|
| 295 |
throw new AccessFileWriteableException('No write permissions for ' . $sPagesDir . $sParentDir);
|
|
| 258 | 296 |
} |
| 259 |
} else |
|
| 260 |
{
|
|
| 297 |
} else {
|
|
| 261 | 298 |
// if parentdir not exists |
| 262 |
if (file_exists($sPagesDir . $sParentDir . $sExtension)) |
|
| 263 |
{
|
|
| 299 |
if (file_exists($sPagesDir . $sParentDir . $sExtension)) {
|
|
| 264 | 300 |
// but parentaccessfile exists, create parentdir and ok |
| 265 | 301 |
$iOldUmask = umask(0); |
| 266 |
$bRetval = mkdir($sPagesDir . $sParentDir, $this->_oReg->OctalDirMode);
|
|
| 302 |
$bRetval = mkdir($sPagesDir . $sParentDir, $this->oReg->OctalDirMode); |
|
| 267 | 303 |
umask($iOldUmask); |
| 268 | 304 |
} else {
|
| 269 |
throw new AccessFileInvalidStructureException('invalid structure ' . $sFilename);
|
|
| 305 |
throw new AccessFileInvalidStructureException('invalid structure - missing file: ' . $sFilename);
|
|
| 270 | 306 |
} |
| 271 | 307 |
if (!$bRetval) {
|
| 272 |
throw new AccessFileNotWriteableException('Unable to create ' . $sPagesDir . $sParentDir);
|
|
| 308 |
throw new AccessFileWriteableException('Unable to create ' . $sPagesDir . $sParentDir);
|
|
| 273 | 309 |
} |
| 274 | 310 |
} |
| 275 | 311 |
} |
| ... | ... | |
| 281 | 317 |
* @return string printable value |
| 282 | 318 |
* @throws InvalidArgumentException |
| 283 | 319 |
*/ |
| 284 |
protected function _sanitizeValue($mValue, $sType)
|
|
| 320 |
protected function sanitizeValue($mValue, $sType) |
|
| 285 | 321 |
{
|
| 286 | 322 |
$mRetval = ''; |
| 287 | 323 |
switch ($sType) |
| ... | ... | |
| 314 | 350 |
* Calculate backsteps in directory |
| 315 | 351 |
* @param string accessfile |
| 316 | 352 |
*/ |
| 317 |
protected function _buildPathToIndexFile($sFileName)
|
|
| 353 |
protected function buildPathToIndexFile($sFileName) |
|
| 318 | 354 |
{
|
| 319 |
$iBackSteps = substr_count(str_replace($this->_oReg->AppPath, '', $sFileName), '/');
|
|
| 355 |
$iBackSteps = substr_count(str_replace($this->oReg->AppPath, '', $sFileName), '/'); |
|
| 320 | 356 |
return str_repeat('../', $iBackSteps) . 'index.php';
|
| 321 | 357 |
} |
| 322 | 358 |
|
| ... | ... | |
| 325 | 361 |
* @param string $sIndexFile name and path to the wb/index.php file |
| 326 | 362 |
* @return string |
| 327 | 363 |
*/ |
| 328 |
protected function _buildFileContent($sIndexFile)
|
|
| 364 |
protected function buildFileContent($sIndexFile) |
|
| 329 | 365 |
{
|
| 330 | 366 |
$sFileContent |
| 331 | 367 |
= '<?php' . "\n" |
| 332 | 368 |
. '// *** This file was created automatically by ' ."\n" |
| 333 |
. '// *** ' . $this->_oReg->AppName . ' Ver.' . $this->_oReg->AppVersion
|
|
| 334 |
. ($this->_oReg->AppServicePack != '' ? ' '.$this->_oReg->AppServicePack : '')
|
|
| 335 |
. ' Rev.' . $this->_oReg->AppRevision . "\n"
|
|
| 369 |
. '// *** ' . $this->oReg->AppName . ' Ver.' . $this->oReg->AppVersion
|
|
| 370 |
. ($this->oReg->AppServicePack != '' ? ' '.$this->oReg->AppServicePack : '')
|
|
| 371 |
. ' Rev.' . $this->oReg->AppRevision . "\n" |
|
| 336 | 372 |
. '// *** on ' . date('c') . "\n"
|
| 337 | 373 |
. '//' . "\n" |
| 338 | 374 |
. '// *** Warning *************************************' . "\n" |
| ... | ... | |
| 341 | 377 |
. '// *** then all manual changes will get lost!!' . "\n" |
| 342 | 378 |
. '// *************************************************' . "\n" |
| 343 | 379 |
. '//' . "\n"; |
| 344 |
foreach ($this->_aVars as $sKey => $sVar) {
|
|
| 380 |
foreach ($this->aVars as $sKey => $sVar) {
|
|
| 345 | 381 |
$sFileContent .= "\t" . '$' . $sKey . ' = ' . $sVar . ';' . "\n"; |
| 346 | 382 |
} |
| 347 |
foreach ($this->_aConsts as $sKey => $sVar) {
|
|
| 383 |
foreach ($this->aConsts as $sKey => $sVar) {
|
|
| 348 | 384 |
$sFileContent .= "\t" . 'define(\'' . $sKey . '\', ' . $sVar . '); // ** deprecated command **' . "\n"; |
| 349 | 385 |
} |
| 350 | 386 |
$sFileContent |
| 351 | 387 |
.="\t" . 'require(\'' . $sIndexFile . '\');' . "\n" |
| 352 |
. "\t" . 'exit(0);' . "\n"
|
|
| 388 |
. "\t" . 'exit();' . "\n" |
|
| 353 | 389 |
. '// *************************************************' . "\n" |
| 354 | 390 |
. '// end of file' . "\n"; |
| 355 |
|
|
| 356 | 391 |
return $sFileContent; |
| 357 | 392 |
} |
| 358 | 393 |
|
| ... | ... | |
| 374 | 409 |
* @description Exceptionhandler for the Accessfiles and depending classes |
| 375 | 410 |
*/ |
| 376 | 411 |
|
| 377 |
class AccessFileException extends Exception { }
|
|
| 412 |
class AccessFileException extends AppException { }
|
|
| 413 |
class AccessFileInvalidStructureException extends AccessFileException { }
|
|
| 414 |
class AccessFileIsNoAccessfileException extends AccessFileException { }
|
|
| 378 | 415 |
class AccessFileConstForbiddenException extends AccessFileException { }
|
| 379 | 416 |
class AccessFileInvalidFilePathException extends AccessFileException { }
|
| 380 |
class AccessFileInvalidFilenameException extends AccessFileException { }
|
|
| 381 |
class AccessFileAlreadyExistsException extends AccessFileException { }
|
|
| 382 |
class AccessFileNotWriteableException extends AccessFileException { }
|
|
| 383 |
class AccessFileIsInvalidFilenameException extends AccessFileException { }
|
|
| 384 |
class AccessFileIsNoAccessfileException extends AccessFileException { }
|
|
| 385 |
class AccessFileInvalidStructureException extends AccessFileException { }
|
|
| 386 | 417 |
class AccessFileRenameException extends AccessFileException { }
|
| 418 |
class AccessFileWriteableException extends AccessFileException { }
|
|
| branches/2.8.x/wb/framework/functions.php | ||
|---|---|---|
| 35 | 35 |
*/ |
| 36 | 36 |
function DeleteAccessFilesTree($sDirToDelete, array &$aReport = null) |
| 37 | 37 |
{
|
| 38 |
$aReport = array();
|
|
| 39 |
$sBaseDir = realpath($sDirToDelete);
|
|
| 40 |
if( $sBaseDir !== false) {
|
|
| 38 |
$aReport = array(); |
|
| 39 |
$sBaseDir = realpath($sDirToDelete);
|
|
| 40 |
if( $sBaseDir !== false) {
|
|
| 41 | 41 |
$sBaseDir = rtrim(str_replace('\\', '/', $sBaseDir), '/') . '/';
|
| 42 | 42 |
// scan start directory for access files |
| 43 | 43 |
foreach (glob($sBaseDir . '*.php', GLOB_MARK) as $sItem) {
|
| 44 | 44 |
$sItem = str_replace('\\', '/', $sItem);
|
| 45 | 45 |
try{
|
| 46 |
$oAccFile = new AccessFile($sItem);
|
|
| 46 |
$oAccFile = new AccessFile($sBaseDir, basename($sItem));
|
|
| 47 | 47 |
$oAccFile->delete(); |
| 48 | 48 |
$aReport = array_merge($aReport, AccessFileHelper::getDelTreeLog()); |
| 49 | 49 |
}catch(AccessFileIsNoAccessfileException $e) {
|
| 50 | 50 |
continue; |
| 51 | 51 |
} |
| 52 | 52 |
} |
| 53 |
clearstatcache();
|
|
| 53 |
clearstatcache();
|
|
| 54 | 54 |
return true; |
| 55 | 55 |
} |
| 56 | 56 |
return false; |
| ... | ... | |
| 706 | 706 |
|
| 707 | 707 |
|
| 708 | 708 |
// Create a new directory and/or protected file in the given directory |
| 709 |
function createFolderProtectFile($sAbsDir='',$make_dir=true) |
|
| 709 |
function createFolderProtectFile($sAbsDir='', $make_dir=true)
|
|
| 710 | 710 |
{
|
| 711 |
global $admin, $MESSAGE; |
|
| 712 |
$retVal = array(); |
|
| 713 |
$wb_path = rtrim(str_replace('\/\\', '/', WB_PATH), '/');
|
|
| 714 |
$sAppPath = rtrim(str_replace('\/\\', '/', WB_PATH), '/').'/';
|
|
| 715 |
if( ($sAbsDir=='') || ($sAbsDir == $sAppPath) ) { return $retVal;}
|
|
| 716 |
|
|
| 717 |
if ( $make_dir==true ) {
|
|
| 711 |
$retVal = array(); |
|
| 712 |
$oReg = WbAdaptor::getInstance(); |
|
| 713 |
$oTrans = Translate::getInstance(); |
|
| 714 |
$sAbsDir = rtrim(str_replace('\\', '/', trim($sAbsDir)), '/').'/';
|
|
| 715 |
if(($sAbsDir=='/') || ($sAbsDir == $oReg->AppPath)) |
|
| 716 |
{
|
|
| 717 |
return $retVal; |
|
| 718 |
} |
|
| 719 |
if($make_dir==true) |
|
| 720 |
{
|
|
| 718 | 721 |
// Check to see if the folder already exists |
| 719 | 722 |
if(is_readable($sAbsDir)) {
|
| 720 |
$retVal[] = basename($sAbsDir).'::'.$MESSAGE['MEDIA_DIR_EXISTS'];
|
|
| 723 |
$retVal[] = basename($sAbsDir).'::'.$oTrans->MESSAGE_MEDIA_DIR_EXISTS;
|
|
| 721 | 724 |
} |
| 722 |
if (!make_dir($sAbsDir) && !is_dir($sAbsDir) ) {
|
|
| 723 |
$retVal[] = basename($sAbsDir).'::'.$MESSAGE['MEDIA_DIR_NOT_MADE']; |
|
| 724 |
} else {
|
|
| 725 |
if(!make_dir($sAbsDir) && !is_dir($sAbsDir)) |
|
| 726 |
{
|
|
| 727 |
$retVal[] = basename($sAbsDir).'::'.$oTrans->MESSAGE_MEDIA_DIR_NOT_MADE; |
|
| 728 |
}else |
|
| 729 |
{
|
|
| 725 | 730 |
change_mode($sAbsDir); |
| 726 | 731 |
} |
| 727 | 732 |
return $retVal; |
| 728 | 733 |
} |
| 729 |
|
|
| 730 |
//$retVal[] = $sAbsDir; |
|
| 731 |
//return $retVal; |
|
| 732 |
|
|
| 733 |
if( is_writable($sAbsDir) ) |
|
| 734 |
if(is_writable($sAbsDir)) |
|
| 734 | 735 |
{
|
| 735 |
// if(file_exists($sAbsDir.'/index.php')) { unlink($sAbsDir.'/index.php'); }
|
|
| 736 |
// Create default "index.php" file |
|
| 737 |
$iBackSteps = substr_count(str_replace($sAppPath, '', $sAbsDir), '/'); |
|
| 738 |
$sIndexFile = str_repeat('../', $iBackSteps).'index.php';
|
|
| 739 | 736 |
$sResponse = $_SERVER['SERVER_PROTOCOL'].' 301 Moved Permanently'; |
| 737 |
// build file content |
|
| 740 | 738 |
$content = |
| 741 | 739 |
'<?php'."\n". |
| 742 |
'// *** This file is generated by WebsiteBaker Ver.'.VERSION."\n".
|
|
| 740 |
'// *** This file is generated by WebsiteBaker Ver.'.$oReg->AppVersion."\n".
|
|
| 743 | 741 |
'// *** Creation date: '.date('c')."\n".
|
| 744 | 742 |
'// *** Do not modify this file manually'."\n". |
| 745 | 743 |
'// *** WB will rebuild this file from time to time!!'."\n". |
| 746 | 744 |
'// *************************************************'."\n". |
| 747 | 745 |
"\t".'header(\''.$sResponse.'\');'."\n". |
| 748 |
"\t".'header(\'Location: '.WB_URL.'/index.php\');'."\n".
|
|
| 746 |
"\t".'header(\'Location: '.$oReg->AppUrl.'index.php\');'."\n".
|
|
| 749 | 747 |
'// *************************************************'."\n"; |
| 750 | 748 |
$filename = $sAbsDir.'/index.php'; |
| 751 |
|
|
| 752 |
// write content into file |
|
| 753 |
if(is_writable($filename) || !file_exists($filename)) {
|
|
| 754 |
if(file_put_contents($filename, $content)) {
|
|
| 755 |
$retVal[] = change_mode($filename); |
|
| 756 |
} else {
|
|
| 757 |
$retVal[] = $MESSAGE['GENERIC_BAD_PERMISSIONS'].' :: '.$filename; |
|
| 758 |
} |
|
| 759 |
} |
|
| 760 |
} else {
|
|
| 761 |
$retVal[] = $MESSAGE['GENERIC_BAD_PERMISSIONS']; |
|
| 762 |
} |
|
| 763 |
return $retVal; |
|
| 749 |
// write content into file |
|
| 750 |
if(is_writable($filename) || !file_exists($filename)) |
|
| 751 |
{
|
|
| 752 |
if(file_put_contents($filename, $content)) |
|
| 753 |
{
|
|
| 754 |
$retVal[] = change_mode($filename); |
|
| 755 |
}else |
|
| 756 |
{
|
|
| 757 |
$retVal[] = $oTrans->MESSAGE_GENERIC_BAD_PERMISSIONS.' :: '.$filename; |
|
| 758 |
} |
|
| 759 |
} |
|
| 760 |
}else |
|
| 761 |
{
|
|
| 762 |
$retVal[] = $oTrans->MESSAGE_GENERIC_BAD_PERMISSIONS; |
|
| 763 |
} |
|
| 764 |
return $retVal; |
|
| 764 | 765 |
} |
| 765 | 766 |
|
| 766 | 767 |
function rebuildFolderProtectFile($dir='') |
| ... | ... | |
| 1449 | 1450 |
|
| 1450 | 1451 |
if(!function_exists('rebuild_all_accessfiles'))
|
| 1451 | 1452 |
{
|
| 1452 |
function rebuild_all_accessfiles($bShowDetails=false )
|
|
| 1453 |
function rebuild_all_accessfiles($bShowDetails=false ) |
|
| 1453 | 1454 |
{
|
| 1454 | 1455 |
$oDb = WbDatabase::getInstance(); |
| 1455 | 1456 |
$oReg = WbAdaptor::getInstance(); |
| 1456 |
$aRetval = array(); |
|
| 1457 | 1457 |
// try to remove access files and build new folder protect files |
| 1458 | 1458 |
$sTreeToDelete = $oReg->AppPath.$oReg->PagesDir; |
| 1459 |
|
|
| 1460 | 1459 |
if(($sTreeToDelete!='') && is_writeable($sTreeToDelete)==true) |
| 1461 | 1460 |
{
|
| 1462 | 1461 |
$aDeleteLog = array(); |
| ... | ... | |
| 1464 | 1463 |
// show details if debug is set |
| 1465 | 1464 |
if($bShowDetails) { $aRetval = $aDeleteLog; }
|
| 1466 | 1465 |
} |
| 1466 |
// set logging informations |
|
| 1467 |
$aRetval = array_merge((isset($aRetval) ? $aRetval : array()), |
|
| 1468 |
createFolderProtectFile(rtrim( $oReg->AppPath.$oReg->PagesDir, '/') )); |
|
| 1467 | 1469 |
// Reformat/rebuild all existing access files |
| 1468 | 1470 |
$sql = 'SELECT `page_id`,`root_parent`,`parent`,`link`,`level`,`page_trail` ' |
| 1469 | 1471 |
. 'FROM `'.$oDb->TablePrefix.'pages` ' |
| ... | ... | |
| 1472 | 1474 |
if (($oPage = $oDb->query($sql))) |
| 1473 | 1475 |
{
|
| 1474 | 1476 |
$iFileCounter = 0; |
| 1475 |
// iterate over all existing page records |
|
| 1476 | 1477 |
while (($aPageRecord = $oPage->fetchRow(MYSQL_ASSOC))) |
| 1477 | 1478 |
{
|
| 1478 | 1479 |
// --- begin reorg tree structure ------------------------------------------------ |
| ... | ... | |
| 1480 | 1481 |
$sql = 'SELECT `level`+1 AS `level`, `page_trail` ' |
| 1481 | 1482 |
. 'FROM `'.$oDb->TablePrefix.'pages` ' |
| 1482 | 1483 |
. 'WHERE `page_id`='.$aPageRecord['parent']; |
| 1483 |
// search for parent record |
|
| 1484 | 1484 |
$oParent = $oDb->query($sql); |
| 1485 | 1485 |
if(($aParentRecord = $oParent->fetchRow(MYSQLI_ASSOC))) |
| 1486 | 1486 |
{
|
| ... | ... | |
| 1503 | 1503 |
. 'WHERE `page_id`='.$aPageRecord['page_id']; |
| 1504 | 1504 |
$oDb->query($sql); |
| 1505 | 1505 |
// --- end reorg tree structure -------------------------------------------------- |
| 1506 |
$sFilename = $oReg->AppPath.$oReg->PagesDir.ltrim($aPageRecord['link'],'/').$oReg->PageExtension; |
|
| 1507 |
$oAccessFile = new AccessFile($sFilename, $aPageRecord['page_id']); |
|
| 1506 |
$sPageTreeRoot = $oReg->AppPath.$oReg->PagesDir; |
|
| 1507 |
$sFilename = ($aPageRecord['link']).$oReg->PageExtension; |
|
| 1508 |
$oAccessFile = new AccessFile($sPageTreeRoot, $sFilename, $aPageRecord['page_id']); |
|
| 1508 | 1509 |
$oAccessFile->write(); |
| 1509 | 1510 |
unset($oAccessFile); |
| 1510 | 1511 |
$iFileCounter++; |
| branches/2.8.x/wb/modules/news/Reorg.php | ||
|---|---|---|
| 127 | 127 |
while(($aPost = $oPosts->fetchRow(MYSQL_ASSOC))) |
| 128 | 128 |
{
|
| 129 | 129 |
// sanitize link if there is an old value in database from former versions |
| 130 |
$aPost['link'] = trim( str_replace('\\', '/', $aPost['link']), '/');
|
|
| 131 | 130 |
$aPost['link'] = preg_replace( '/^'.preg_quote($this->sAccessFilesSubdir, '/').'/', |
| 132 | 131 |
'', |
| 133 | 132 |
trim( str_replace('\\', '/', $aPost['link']), '/')
|
| 134 | 133 |
); |
| 134 |
|
|
| 135 | 135 |
// compose name of accessfile |
| 136 | 136 |
$sAccFileName = $this->sAccessFilesRoot.$aPost['link'].$this->oReg->PageExtension; |
| 137 |
|
|
| 137 | 138 |
try |
| 138 | 139 |
{
|
| 139 | 140 |
// create new object |
| 140 |
$oAccFile = new AccessFile($sAccFileName, $aPost['page_id']);
|
|
| 141 |
$oAccFile = new AccessFile($this->sAccessFilesRoot, $aPost['link'], $aPost['page_id']);
|
|
| 141 | 142 |
$oAccFile->addVar('section_id', $aPost['section_id'], AccessFile::VAR_INT);
|
| 142 | 143 |
$oAccFile->addVar('post_id', $aPost['post_id'], AccessFile::VAR_INT);
|
| 143 | 144 |
$oAccFile->addVar('post_section', $aPost['section_id'], AccessFile::VAR_INT);
|
Also available in: Unified diff
! update Access Files Classes with easier handling
for modules who create their own accessfiles