Project

General

Profile

« Previous | Next » 

Revision 1977

Added by Dietmar about 11 years ago

! /framework/functions.php: started implementation of packet AccessFile in function rebuild_all_accessfiles()
+ /framework/functions.php::rm_full_dir() added additional argument to set list of protected files
! integrate the new processes into the upgrade-script.php
+ extended checks and informations in /modules/MultiLingual/upgrade.php
increasing version for module MultiLingual to 1.6.9

View differences:

functions.php
24 24
// Define that this file has been loaded
25 25
define('FUNCTIONS_FILE_LOADED', true);
26 26

  
27

  
27 28
/**
29
 * Delete an Accessfiles Tree
30
 * @param  string  $sDirToDelete  
31
 * @return boolean true/false
32
 * @description    Delete all accessfiles and its depending directory tree 
33
 *                 inside the given directory.
34
 */
35

  
36
function DeleteAccessFilesTree($sDirToDelete)
37
{
38
        $sBaseDir = realpath($sDirToDelete);
39
        if( $sBaseDir !== false) {    
40
		$sBaseDir = rtrim(str_replace('\\', '/', $sBaseDir), '/') . '/';
41
		// scan start directory for access files
42
		foreach (glob($sBaseDir . '*.php', GLOB_MARK) as $sItem) {
43
            $sItem = str_replace('\\', '/', $sItem);
44
			try{
45
				$oAccFile = new AccessFile($sItem);
46
				$oAccFile->delete();
47
			}catch(AccessFileIsNoAccessfileException $e) {
48
				continue;
49
			}
50
		}
51
		return true;
52
	}	
53
	return false;
54
}
55

  
56
/**
28 57
 * @description: recursively delete a non empty directory
29 58
 * @param string $directory :
30 59
 * @param bool $empty : true if you want the folder just emptied, but not deleted
31 60
 *                      false, or just simply leave it out, the given directory will be deleted, as well
61
 * @param array $aProtectedFiles optional list of protected files, full path needed
32 62
 * @return boolean: true/false
33 63
 * @from http://www.php.net/manual/de/function.rmdir.php#98499
34 64
 */
35
function rm_full_dir($directory, $empty = false)
65
function rm_full_dir($directory, $empty = false, $aProtectedFiles = null)
36 66
{
67
	$directory = rtrim(str_replace('\\','/',$directory),'/');
68
	if($aProtectedFiles == null) {
69
		$aProtectedFiles = array();
70
	}
37 71
    $iErrorReporting = error_reporting(0);
38
	if(substr($directory,-1) == "/") {
39
        $directory = substr($directory,0,-1);
40
    }
41
   // If suplied dirname is a file then unlink it
72

  
42 73
    if (is_file( $directory )&& is_writable( $directory )) {
43
        $retval = unlink($directory);
44
        clearstatcache();
45
        error_reporting($iErrorReporting);
46
        return $retval;
74
		if(!in_array(($directory), $aProtectedFiles)) {
75
			$retval = unlink($directory);
76
			clearstatcache();
77
			error_reporting($iErrorReporting);
78
			return $retval;
79
		}else {
80
			return true;
81
		}
47 82
    }
48 83
    if(!is_writable($directory) || !is_dir($directory)) {
49 84
        error_reporting($iErrorReporting);
......
59 94
			{
60 95
                $path = $directory . "/" . $contents;
61 96
                if(is_dir($path)) {
62
                    rm_full_dir($path);
97
                    rm_full_dir($path, false, $aProtectedFiles);
63 98
                } else {
64
                    unlink($path);
65
					clearstatcache();
99
					if(!in_array($path, $aProtectedFiles)) {
100
				        unlink($path);
101
						clearstatcache();
102
					}
66 103
                }
67 104
            }
68 105
        }
......
670 707
{
671 708
	global $admin, $MESSAGE;
672 709
	$retVal = array();
673
	$wb_path = rtrim(str_replace('\/\\', '/', WB_PATH), '/');
674
	if( ($sAbsDir=='') || ($sAbsDir == $wb_path) ) { return $retVal;}
710
	$wb_path   = rtrim(str_replace('\/\\', '/', WB_PATH), '/');
711
	$sAppPath  = rtrim(str_replace('\/\\', '/', WB_PATH), '/').'/';
712
	if( ($sAbsDir=='') || ($sAbsDir == $sAppPath) ) { return $retVal;}
675 713

  
676 714
	if ( $make_dir==true ) {
677 715
		// Check to see if the folder already exists
678 716
		if(is_readable($sAbsDir)) {
679 717
			$retVal[] = basename($sAbsDir).'::'.$MESSAGE['MEDIA_DIR_EXISTS'];
680 718
		}
681
		if (!is_dir($sAbsDir) && !make_dir($sAbsDir) ) {
719
		if (!make_dir($sAbsDir) && !is_dir($sAbsDir) ) {
682 720
			$retVal[] = basename($sAbsDir).'::'.$MESSAGE['MEDIA_DIR_NOT_MADE'];
683 721
		} else {
684 722
			change_mode($sAbsDir);
......
693 731
	{
694 732
        // if(file_exists($sAbsDir.'/index.php')) { unlink($sAbsDir.'/index.php'); }
695 733
	    // Create default "index.php" file
696
		$rel_pages_dir = str_replace($wb_path, '', dirname($sAbsDir) );
697
		$step_back = str_repeat( '../', substr_count($rel_pages_dir, '/')+1 );
734
		$iBackSteps = substr_count(str_replace($sAppPath, '', $sAbsDir), '/');
735
		$sIndexFile = str_repeat('../', $iBackSteps).'index.php';
698 736
		$sResponse  = $_SERVER['SERVER_PROTOCOL'].' 301 Moved Permanently';
699 737
		$content =
700 738
			'<?php'."\n".
......
1407 1445
}
1408 1446

  
1409 1447
if(!function_exists('rebuild_all_accessfiles')){
1410
	function rebuild_all_accessfiles() {
1448
	function rebuild_all_accessfiles($bShowDetails=false ) {
1411 1449
        global $database;
1412
    	$retVal = array();
1450
    	$aRetval = array();
1413 1451
    	/**
1414 1452
    	 * try to remove access files and build new folder protect files
1415 1453
    	 */
1416
    	$sTempDir = (defined('PAGES_DIRECTORY') && (PAGES_DIRECTORY != '') ? PAGES_DIRECTORY : '');
1417
    	if(($sTempDir!='') && is_writeable(WB_PATH.$sTempDir)==true) {
1418
    	 	if(rm_full_dir (WB_PATH.$sTempDir, true )==false) {
1419
    			$retVal[] = 'Could not delete existing access files';
1420
    	 	}
1454
 //   	$sTempDir = (defined('PAGES_DIRECTORY') && (PAGES_DIRECTORY != '') ? PAGES_DIRECTORY : '').'/';
1455
        $sTreeToDelete = WbAdaptor::getInstance()->AppPath.WbAdaptor::getInstance()->PagesDir;
1456
    	if(($sTreeToDelete!='') && is_writeable($sTreeToDelete)==true) {
1457
//    	 	if(rm_full_dir (WB_PATH.$sTempDir, true, $aProtectedFiles )==false) {
1458
//    			$aRetval[] = 'Could not delete existing access files';
1459
//    	 	}
1460
            DeleteAccessFilesTree($sTreeToDelete);
1461
            if($bShowDetails) {
1462
                $aRetval = array_merge($aRetval, AccessFileHelper::getDelTreeLog());
1463
            }
1421 1464
    	}
1422
		$retVal = createFolderProtectFile(rtrim( WB_PATH.PAGES_DIRECTORY,'/') );
1465

  
1466
		$aRetval = array_merge($aRetval,createFolderProtectFile(rtrim( WB_PATH.PAGES_DIRECTORY,'/') ));
1467

  
1423 1468
    	/**
1424 1469
    	 * Reformat/rebuild all existing access files
1425 1470
    	 */
......
1450 1495
                create_access_file($filename, $page['page_id'], $page['level']);
1451 1496
                $x++;
1452 1497
            }
1453
            $retVal[] = 'Number of new formated access files: '.$x.'';
1498
            $aRetval[] = 'Number of new formated access files: '.$x.'';
1454 1499
        }
1455
    return $retVal;
1500
    return $aRetval;
1456 1501
	}
1457 1502
}
1458 1503

  

Also available in: Unified diff