Revision 1866
Added by Dietmar almost 12 years ago
functions.php | ||
---|---|---|
13 | 13 |
* @filesource $HeadURL$ |
14 | 14 |
* @lastmodified $Date$ |
15 | 15 |
* |
16 |
*/ |
|
16 |
*/
|
|
17 | 17 |
/* -------------------------------------------------------- */ |
18 | 18 |
// Must include code to stop this file being accessed directly |
19 | 19 |
if(!defined('WB_PATH')) { |
... | ... | |
415 | 415 |
// Function to create directories |
416 | 416 |
function make_dir($dir_name, $dir_mode = OCTAL_DIR_MODE, $recursive=true) |
417 | 417 |
{ |
418 |
$retVal = is_dir($dir_name);
|
|
419 |
if(!is_dir($dir_name))
|
|
418 |
$bRetval = is_dir($dir_name);
|
|
419 |
if(!$bRetval)
|
|
420 | 420 |
{ |
421 | 421 |
// To create the folder with 0777 permissions, we need to set umask to zero. |
422 | 422 |
$oldumask = umask(0) ; |
423 |
$retVal = mkdir($dir_name, $dir_mode, $recursive);
|
|
423 |
$bRetval = mkdir($dir_name, $dir_mode|0711, $recursive);
|
|
424 | 424 |
umask( $oldumask ) ; |
425 | 425 |
} |
426 |
return $retVal;
|
|
426 |
return $bRetval;
|
|
427 | 427 |
} |
428 | 428 |
|
429 | 429 |
/** |
... | ... | |
433 | 433 |
* @param int rights in dec-value. 0= use wb-defaults |
434 | 434 |
* @return bool |
435 | 435 |
*/ |
436 |
function change_mode($sName, $iMode = 0) |
|
436 |
function change_mode($sName, $iMode = 0 )
|
|
437 | 437 |
{ |
438 | 438 |
$bRetval = true; |
439 | 439 |
$iErrorReporting = error_reporting(0); |
... | ... | |
653 | 653 |
} |
654 | 654 |
} |
655 | 655 |
|
656 |
|
|
656 | 657 |
// Create a new directory and/or protected file in the given directory |
657 | 658 |
function createFolderProtectFile($sAbsDir='',$make_dir=true) |
658 | 659 |
{ |
... | ... | |
663 | 664 |
|
664 | 665 |
if ( $make_dir==true ) { |
665 | 666 |
// Check to see if the folder already exists |
666 |
if(file_exists($sAbsDir)) { |
|
667 |
// $admin->print_error($MESSAGE['MEDIA_DIR_EXISTS']); |
|
667 |
if(is_readable($sAbsDir)) { |
|
668 | 668 |
$retVal[] = basename($sAbsDir).'::'.$MESSAGE['MEDIA_DIR_EXISTS']; |
669 | 669 |
} |
670 | 670 |
if (!is_dir($sAbsDir) && !make_dir($sAbsDir) ) { |
671 |
// $admin->print_error($MESSAGE['MEDIA_DIR_NOT_MADE']); |
|
672 | 671 |
$retVal[] = basename($sAbsDir).'::'.$MESSAGE['MEDIA_DIR_NOT_MADE']; |
673 | 672 |
} else { |
674 | 673 |
change_mode($sAbsDir); |
675 | 674 |
} |
675 |
return $retVal; |
|
676 | 676 |
} |
677 | 677 |
|
678 | 678 |
if( is_writable($sAbsDir) ) |
... | ... | |
698 | 698 |
// write content into file |
699 | 699 |
if(is_writable($filename) || !file_exists($filename)) { |
700 | 700 |
if(file_put_contents($filename, $content)) { |
701 |
// print 'create => '.str_replace( $wb_path,'',$filename).'<br />'; |
|
702 |
change_mode($filename, 'file'); |
|
701 |
$retVal[] = change_mode($filename); |
|
703 | 702 |
} else { |
704 | 703 |
$retVal[] = $MESSAGE['GENERIC_BAD_PERMISSIONS'].' :: '.$filename; |
705 | 704 |
} |
... | ... | |
714 | 713 |
{ |
715 | 714 |
global $MESSAGE; |
716 | 715 |
$retVal = array(); |
716 |
$tmpVal = array(); |
|
717 | 717 |
$dir = rtrim(str_replace('\/\\', '/', $dir), '/'); |
718 | 718 |
try { |
719 | 719 |
$files = array(); |
... | ... | |
724 | 724 |
$files = array_unique($files); |
725 | 725 |
foreach( $files as $file) { |
726 | 726 |
$protect_file = rtrim(str_replace('\/\\', '/', $file), '/'); |
727 |
$retVal[] = createFolderProtectFile($protect_file,false);
|
|
727 |
$tmpVal['file'][] = createFolderProtectFile($protect_file,false);
|
|
728 | 728 |
} |
729 |
$retVal = $tmpVal['file']; |
|
729 | 730 |
} catch ( Exception $e ) { |
730 | 731 |
$retVal[] = $MESSAGE['MEDIA_DIR_ACCESS_DENIED']; |
731 | 732 |
} |
... | ... | |
733 | 734 |
} |
734 | 735 |
|
735 | 736 |
// Create a new file in the pages directory |
736 |
function create_access_file($filename,$page_id,$level) |
|
737 |
/** |
|
738 |
* createAccessFile() |
|
739 |
* |
|
740 |
* @param string The full path and filename to the new accessfile |
|
741 |
* @param int Id of the page for which the file should created |
|
742 |
* @param mixed an array with one or more additional statements to include in accessfile. |
|
743 |
* @return bool|string true or error message |
|
744 |
* @deprecated this function will be replaced by a core method in next version |
|
745 |
* @description: Create a new access file in the pages directory and subdirectory also if needed.<br /> |
|
746 |
* Example: $aOptionalCommands = array( |
|
747 |
* '$section_id = '.$section_id, |
|
748 |
* '$mod_var_int = '.$mod_var_int, |
|
749 |
* 'define(\'MOD_CONSTANT\'', '.$mod_var_int.')' |
|
750 |
* ); |
|
751 |
* forbidden commands: include|require[_once] |
|
752 |
* @deprecated 2013/02/19 |
|
753 |
*/ |
|
754 |
|
|
755 |
function create_access_file($sFileName, $iPageId, $iLevel = 0, array $aOptionalCommands = array() ) |
|
737 | 756 |
{ |
738 |
global $admin, $MESSAGE; |
|
739 |
$retVal = array(); |
|
740 |
// First make sure parent folder exists |
|
741 |
$parent_folders = explode('/',str_replace(WB_PATH.PAGES_DIRECTORY, '', dirname($filename))); |
|
742 |
$parents = ''; |
|
743 |
foreach($parent_folders AS $parent_folder) |
|
744 |
{ |
|
745 |
if($parent_folder != '/' AND $parent_folder != '') |
|
757 |
global $MESSAGE; |
|
758 |
$sError = ''; |
|
759 |
// sanitize pathnames for the standard 'trailing slash' scheme |
|
760 |
$sAppPath = rtrim(str_replace('\\', '/', WB_PATH), '/').'/'; |
|
761 |
$sFileName = str_replace('\\', '/', $sFileName); |
|
762 |
// try to create the whoole path to the accessfile |
|
763 |
$sAccessPath = dirname($sFileName).'/'; |
|
764 |
if(!($bRetval = is_dir($sAccessPath))) { |
|
765 |
$iOldUmask = umask(0) ; |
|
766 |
// sanitize directory mode to 'o+rwx/g+x/u+x' and create path |
|
767 |
$bRetval = mkdir($sAccessPath, (OCTAL_DIR_MODE |0711), true); |
|
768 |
umask($iOldUmask); |
|
769 |
} |
|
770 |
if($bRetval) { |
|
771 |
// check if accessfile is writeable |
|
772 |
if(is_writable($sAccessPath) || |
|
773 |
(file_exists($sFileName) && is_writable($sFileName)) ) |
|
746 | 774 |
{ |
747 |
$parents .= '/'.$parent_folder; |
|
748 |
$acces_file = WB_PATH.PAGES_DIRECTORY.$parents; |
|
749 |
// can only be dirs |
|
750 |
if(!is_readable($acces_file)) { |
|
751 |
if(!make_dir($acces_file)) { |
|
752 |
$retVal[] = $MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE_FOLDER']; |
|
753 |
$retVal[] = $MESSAGE['MEDIA_DIR_ACCESS_DENIED']; |
|
775 |
// build content for accessfile |
|
776 |
$sContent = '<?php'."\n" |
|
777 |
. '// *** This file is generated by WebsiteBaker Ver.'.VERSION."\n" |
|
778 |
. '// *** Creation date: '.date('c')."\n" |
|
779 |
. '// *** Do not modify this file manually'."\n" |
|
780 |
. '// *** WB will rebuild this file from time to time!!'."\n" |
|
781 |
. '// *************************************************'."\n" |
|
782 |
. "\t".'$page_id = '.$iPageId.';'."\n"; |
|
783 |
// analyse OptionalCommands and add it to the accessfile |
|
784 |
foreach($aOptionalCommands as $sCommand) { |
|
785 |
// loop through all available entries |
|
786 |
// remove all leading whitespaces and chars less then \x41(A) except \x24 ($) |
|
787 |
// also all trailing whitespaces and \x3B(;) too. |
|
788 |
$sNewCmd = rtrim(ltrim($sCommand, "\x00..\x23\x25..\x40"), ';'); |
|
789 |
if(preg_match('/^include|^require/i', $sNewCmd)) { |
|
790 |
// insert forbidden include|require[_once] command and comment it out |
|
791 |
$sContent .= "\t".'// *not allowed command >> * '.$sNewCmd.';'."\n"; |
|
792 |
}elseif(preg_match('/^define/i', $sNewCmd)) { |
|
793 |
// insert active define command and comment it as set deprecated |
|
794 |
$sContent .= "\t".$sNewCmd.'; // *deprecated command*'."\n"; |
|
795 |
}else { |
|
796 |
// insert allowed active command |
|
797 |
$sContent .= "\t".$sNewCmd.';'."\n"; |
|
754 | 798 |
} |
755 | 799 |
} |
800 |
// calculate the needed backsteps and create the relative link to index.php |
|
801 |
$iBackSteps = substr_count(str_replace($sAppPath, '', $sFileName), '/'); |
|
802 |
$sIndexFile = str_repeat('../', $iBackSteps).'index.php'; |
|
803 |
// insert needed require command for index.php |
|
804 |
$sContent .= "\t".'require(\''.$sIndexFile.'\');'."\n" |
|
805 |
. '// *************************************************'."\n" |
|
806 |
. '// end of file'."\n"; |
|
807 |
// write new file out. If the file already exists overwrite its content. |
|
808 |
if(file_put_contents($sFileName, $sContent) !== false ) { |
|
809 |
// if OS is not windows then chmod the new file |
|
810 |
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { |
|
811 |
// sanitize filemode to 'o-x/g-x/u-x/o+rw' and chmod the new file |
|
812 |
$bRetval = chmod($sName, ((OCTAL_FILE_MODE & ~0111)|0600)); |
|
813 |
} |
|
814 |
}else { |
|
815 |
$sError = $MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']; |
|
816 |
} |
|
817 |
}else { |
|
818 |
$sError = $MESSAGE['UPLOAD_ERR_CANT_WRITE']; |
|
756 | 819 |
} |
820 |
}else { |
|
821 |
$sError = $MESSAGE['UPLOAD_ERR_CANT_WRITE']; |
|
757 | 822 |
} |
758 |
|
|
759 |
// The depth of the page directory in the directory hierarchy |
|
760 |
// '/pages' is at depth 2 |
|
761 |
$bPagesDirectorySet = (sizeof(explode('/',PAGES_DIRECTORY))==1); |
|
762 |
// Work-out how many ../'s we need to get to the index page |
|
763 |
$pages_dir_depth = sizeof($parent_folders)-intval($bPagesDirectorySet); |
|
764 |
$index_location = str_repeat ( '../' , $pages_dir_depth ); |
|
765 |
$content = |
|
766 |
'<?php'."\n". |
|
767 |
'// *** This file is generated by WebsiteBaker Ver.'.VERSION."\n". |
|
768 |
'// *** Creation date: '.date('c')."\n". |
|
769 |
'// *** Do not modify this file manually'."\n". |
|
770 |
'// *** WB will rebuild this file from time to time!!'."\n". |
|
771 |
'// *************************************************'."\n". |
|
772 |
"\t".'$page_id = '.$page_id.';'."\n". |
|
773 |
"\t".'require(\''.$index_location.'index.php\');'."\n". |
|
774 |
'// *************************************************'."\n"; |
|
775 |
|
|
776 |
if( ($handle = fopen($filename, 'w')) ) { |
|
777 |
fwrite($handle, $content); |
|
778 |
fclose($handle); |
|
779 |
// Chmod the file |
|
780 |
change_mode($filename); |
|
781 |
} else { |
|
782 |
// $admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']); |
|
783 |
$retVal[] = $MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']; |
|
784 |
} |
|
785 |
return $retVal; |
|
823 |
// return boolean true if ok, on error return a message |
|
824 |
return ($sError == '' ? true : $sError); |
|
786 | 825 |
} |
787 | 826 |
|
788 | 827 |
// Function for working out a file mime type (if the in-built PHP one is not enabled) |
... | ... | |
1348 | 1387 |
* try to remove access files and build new folder protect files |
1349 | 1388 |
*/ |
1350 | 1389 |
$sTempDir = (defined('PAGES_DIRECTORY') && (PAGES_DIRECTORY != '') ? PAGES_DIRECTORY : ''); |
1351 |
if(($sTempDir!='') && is_writeable(WB_PATH.$sTempDir)==true) { |
|
1352 |
if(rm_full_dir (WB_PATH.$sTempDir, true )==false) { |
|
1353 |
$retVal[] = '<span><strong>Could not delete existing access files</strong></span>';
|
|
1354 |
} |
|
1355 |
} |
|
1356 |
$retVal[] = createFolderProtectFile(rtrim( WB_PATH.PAGES_DIRECTORY,'/') );
|
|
1390 |
// if(($sTempDir!='') && is_writeable(WB_PATH.$sTempDir)==true) {
|
|
1391 |
// if(rm_full_dir (WB_PATH.$sTempDir, true )==false) {
|
|
1392 |
// $retVal[] = 'Could not delete existing access files';
|
|
1393 |
// }
|
|
1394 |
// }
|
|
1395 |
$retVal = createFolderProtectFile(rtrim( WB_PATH.PAGES_DIRECTORY,'/') ); |
|
1357 | 1396 |
/** |
1358 | 1397 |
* Reformat/rebuild all existing access files |
1359 | 1398 |
*/ |
1360 |
$sql = 'SELECT `page_id`,`root_parent`,`link`, `level` FROM `'.TABLE_PREFIX.'pages` ORDER BY `link`'; |
|
1399 |
// $sql = 'SELECT `page_id`,`root_parent`,`link`, `level` FROM `'.TABLE_PREFIX.'pages` ORDER BY `link`'; |
|
1400 |
$sql = 'SELECT `page_id`,`root_parent`,`link`, `level` '; |
|
1401 |
$sql .= 'FROM `'.TABLE_PREFIX.'pages` '; |
|
1402 |
$sql .= 'WHERE `link` != \'\' ORDER BY `link` '; |
|
1361 | 1403 |
if (($oPage = $database->query($sql))) |
1362 | 1404 |
{ |
1363 | 1405 |
$x = 0; |
... | ... | |
1378 | 1420 |
|
1379 | 1421 |
if(!$database->query($sql)) {} |
1380 | 1422 |
$filename = WB_PATH.PAGES_DIRECTORY.$page['link'].PAGE_EXTENSION; |
1381 |
$retVal = create_access_file($filename, $page['page_id'], $page['level']);
|
|
1423 |
create_access_file($filename, $page['page_id'], $page['level']); |
|
1382 | 1424 |
$x++; |
1383 | 1425 |
} |
1384 |
$retVal[] = '<span><strong>Number of new formated access files: '.$x.'</strong></span>';
|
|
1426 |
$retVal[] = 'Number of new formated access files: '.$x.'';
|
|
1385 | 1427 |
} |
1386 | 1428 |
return $retVal; |
1387 | 1429 |
} |
... | ... | |
1395 | 1437 |
$currModulVersion = get_modul_version ($sModul, false); |
1396 | 1438 |
$newModulVersion = get_modul_version ($sModul, true); |
1397 | 1439 |
if((version_compare($currModulVersion, $newModulVersion) <= 0)) { |
1398 |
require_once(WB_PATH.'/modules/'.$sModul.'/upgrade.php');
|
|
1440 |
require(WB_PATH.'/modules/'.$sModul.'/upgrade.php'); |
|
1399 | 1441 |
} |
1400 | 1442 |
} |
1401 | 1443 |
} |
Also available in: Unified diff
! framework/functions.php set function create_access_file to deprecated
! set ModLanguage.php to deprecated
! add methode escapeString to class WbDatabase
! update upgrade-script.php
! add getter property LastInsertId to class WbDatabase