Revision 2045
Added by Dietmar almost 11 years ago
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++; |
Also available in: Unified diff
! update Access Files Classes with easier handling
for modules who create their own accessfiles