Revision 1457
Added by Luisehahne over 14 years ago
| functions.php | ||
|---|---|---|
| 676 | 676 |
return $string; |
| 677 | 677 |
} |
| 678 | 678 |
|
| 679 |
// Function to convert a desired media filename to a clean filename |
|
| 679 |
// Function to convert a desired media filename to a clean mediafilename
|
|
| 680 | 680 |
function media_filename($string) |
| 681 | 681 |
{
|
| 682 | 682 |
require_once(WB_PATH.'/framework/functions-utf8.php'); |
| ... | ... | |
| 703 | 703 |
} |
| 704 | 704 |
|
| 705 | 705 |
// Create a new file in the pages directory |
| 706 |
function createFolderProtectFile($relative='',$make_dir=true) |
|
| 707 |
{
|
|
| 708 |
global $admin, $MESSAGE; |
|
| 709 |
$retVal = array(); |
|
| 710 |
if($relative=='') { return $retVal;}
|
|
| 711 |
|
|
| 712 |
if ( $make_dir==true ) {
|
|
| 713 |
// Check to see if the folder already exists |
|
| 714 |
if(file_exists($relative)) {
|
|
| 715 |
// $admin->print_error($MESSAGE['MEDIA_DIR_EXISTS']); |
|
| 716 |
$retVal[] = $MESSAGE['MEDIA_DIR_EXISTS']; |
|
| 717 |
} |
|
| 718 |
if ( !make_dir($relative) ) {
|
|
| 719 |
// $admin->print_error($MESSAGE['MEDIA_DIR_NOT_MADE']); |
|
| 720 |
$retVal[] = $MESSAGE['MEDIA_DIR_NOT_MADE']; |
|
| 721 |
} |
|
| 722 |
} |
|
| 723 |
|
|
| 724 |
change_mode($relative); |
|
| 725 |
if( is_writable($relative) ) |
|
| 726 |
{
|
|
| 727 |
if(file_exists($relative.'/index.php')) { unlink($relative.'/index.php'); }
|
|
| 728 |
// Create default "index.php" file |
|
| 729 |
$rel_pages_dir = str_replace(WB_PATH, '', dirname($relative) ); |
|
| 730 |
$step_back = str_repeat( '../', substr_count($rel_pages_dir, '/')+1 ); |
|
| 731 |
|
|
| 732 |
$sResponse = $_SERVER['SERVER_PROTOCOL'].' 301 Moved Permanently'; |
|
| 733 |
$content = |
|
| 734 |
'<?php'."\n". |
|
| 735 |
'// *** This file is generated by WebsiteBaker Ver.'.VERSION."\n". |
|
| 736 |
'// *** Creation date: '.date('c')."\n".
|
|
| 737 |
'// *** Do not modify this file manually'."\n". |
|
| 738 |
'// *** WB will rebuild this file from time to time!!'."\n". |
|
| 739 |
'// *************************************************'."\n". |
|
| 740 |
"\t".'header(\''.$sResponse.'\');'."\n". |
|
| 741 |
"\t".'header(\'Location: '.WB_URL.'/index.php\');'."\n". |
|
| 742 |
'// *************************************************'."\n"; |
|
| 743 |
$filename = $relative.'/index.php'; |
|
| 744 |
// write content into file |
|
| 745 |
if ($handle = fopen($filename, 'w')) {
|
|
| 746 |
fwrite($handle, $content); |
|
| 747 |
fclose($handle); |
|
| 748 |
change_mode($filename, 'file'); |
|
| 749 |
} |
|
| 750 |
// $admin->print_success($MESSAGE['MEDIA']['DIR_MADE']); |
|
| 751 |
} else {
|
|
| 752 |
// $admin->print_error($MESSAGE['GENERIC_BAD_PERMISSIONS']); |
|
| 753 |
$retVal[] = '::'.$MESSAGE['GENERIC_BAD_PERMISSIONS']; |
|
| 754 |
} |
|
| 755 |
return $retVal; |
|
| 756 |
} |
|
| 757 |
|
|
| 758 |
// Rebuild a new file in the pages directory |
|
| 759 |
function rebuildFolderProtectFile($dir='') |
|
| 760 |
{
|
|
| 761 |
$retVal = array(); |
|
| 762 |
try {
|
|
| 763 |
$iterator = new RecursiveDirectoryIterator($dir); |
|
| 764 |
foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST) as $file) |
|
| 765 |
{
|
|
| 766 |
if ($file->isDir()) {
|
|
| 767 |
$protect_file = ($file->getPathname()); |
|
| 768 |
$retVal[] = createFolderProtectFile($protect_file,false); |
|
| 769 |
} else {
|
|
| 770 |
// print ($file->getPathname())."<br />"; |
|
| 771 |
} |
|
| 772 |
} |
|
| 773 |
} catch ( Exception $e ) {
|
|
| 774 |
$retVal[] = $MESSAGE['MEDIA_DIR_ACCESS_DENIED']; |
|
| 775 |
} |
|
| 776 |
|
|
| 777 |
$retVal = array_merge($retVal); |
|
| 778 |
return $retVal; |
|
| 779 |
} |
|
| 780 |
|
|
| 781 |
// Create a new file in the pages directory |
|
| 706 | 782 |
function create_access_file($filename,$page_id,$level) |
| 707 | 783 |
{
|
| 708 | 784 |
global $admin, $MESSAGE; |
| 785 |
/* |
|
| 709 | 786 |
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) |
| 710 | 787 |
{
|
| 711 | 788 |
$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']); |
| 712 |
} |
|
| 713 |
else
|
|
| 714 |
{
|
|
| 789 |
} else {
|
|
| 790 |
}
|
|
| 791 |
*/
|
|
| 715 | 792 |
// First make sure parent folder exists |
| 716 | 793 |
$parent_folders = explode('/',str_replace(WB_PATH.PAGES_DIRECTORY, '', dirname($filename)));
|
| 717 | 794 |
$parents = ''; |
| ... | ... | |
| 720 | 797 |
if($parent_folder != '/' AND $parent_folder != '') |
| 721 | 798 |
{
|
| 722 | 799 |
$parents .= '/'.$parent_folder; |
| 723 |
if(!file_exists(WB_PATH.PAGES_DIRECTORY.$parents)) |
|
| 724 |
{
|
|
| 725 |
make_dir(WB_PATH.PAGES_DIRECTORY.$parents); |
|
| 800 |
$acces_file = WB_PATH.PAGES_DIRECTORY.$parents; |
|
| 801 |
// can only be dirs |
|
| 802 |
if(!file_exists($acces_file)) {
|
|
| 803 |
if(!make_dir($acces_file)) {
|
|
| 804 |
$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE_FOLDER']); |
|
| 805 |
} |
|
| 726 | 806 |
} |
| 727 |
}
|
|
| 807 |
} |
|
| 728 | 808 |
} |
| 729 | 809 |
// The depth of the page directory in the directory hierarchy |
| 730 | 810 |
// '/pages' is at depth 1 |
| ... | ... | |
| 735 | 815 |
{
|
| 736 | 816 |
$index_location .= '../'; |
| 737 | 817 |
} |
| 738 |
$content = ''. |
|
| 739 |
'<?php |
|
| 740 |
$page_id = '.$page_id.'; |
|
| 741 |
require("'.$index_location.'config.php");
|
|
| 742 |
require(WB_PATH."/index.php"); |
|
| 743 |
?>'; |
|
| 744 |
$handle = fopen($filename, 'w'); |
|
| 745 |
fwrite($handle, $content); |
|
| 746 |
fclose($handle); |
|
| 747 |
// Chmod the file |
|
| 748 |
change_mode($filename); |
|
| 749 |
} |
|
| 750 |
} |
|
| 818 |
$content = |
|
| 819 |
'<?php'."\n". |
|
| 820 |
'// *** This file is generated by WebsiteBaker Ver.'.VERSION."\n". |
|
| 821 |
'// *** Creation date: '.date('c')."\n".
|
|
| 822 |
'// *** Do not modify this file manually'."\n". |
|
| 823 |
'// *** WB will rebuild this file from time to time!!'."\n". |
|
| 824 |
'// *************************************************'."\n". |
|
| 825 |
"\t".'$page_id = '.$page_id.';'."\n". |
|
| 826 |
"\t".'require(\''.$index_location.'index.php\');'."\n". |
|
| 827 |
'// *************************************************'."\n"; |
|
| 751 | 828 |
|
| 829 |
if ($handle = fopen($filename, 'w')) {
|
|
| 830 |
fwrite($handle, $content); |
|
| 831 |
fclose($handle); |
|
| 832 |
// Chmod the file |
|
| 833 |
change_mode($filename); |
|
| 834 |
} else {
|
|
| 835 |
$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']); |
|
| 836 |
} |
|
| 837 |
return; |
|
| 838 |
} |
|
| 839 |
|
|
| 752 | 840 |
// Function for working out a file mime type (if the in-built PHP one is not enabled) |
| 753 | 841 |
if(!function_exists('mime_content_type'))
|
| 754 | 842 |
{
|
| 755 |
function mime_content_type($filename)
|
|
| 843 |
function mime_content_type($filename) |
|
| 756 | 844 |
{
|
| 757 | 845 |
$mime_types = array( |
| 758 | 846 |
'txt' => 'text/plain', |
| 759 | 847 | |
Also available in: Unified diff
Preparing 2.8.2 stable, last tests