Project

General

Profile

1
<?php
2

    
3
// $Id: install.php 915 2009-01-21 19:27:01Z Ruebenwurzel $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2009, Ryan Djurovich
9

    
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14

    
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19

    
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23

    
24
*/
25

    
26
if(defined('WB_URL')) {
27

    
28
    function create_new_post($filename, $filetime=NULL, $content )
29
    {
30
    global $page_id, $section_id, $post_id;
31
	// The depth of the page directory in the directory hierarchy
32
	// '/pages' is at depth 1
33
	$pages_dir_depth = count(explode('/',PAGES_DIRECTORY))-1;
34
	// Work-out how many ../'s we need to get to the index page
35
	$index_location = '../';
36
	for($i = 0; $i < $pages_dir_depth; $i++)
37
    {
38
		$index_location .= '../';
39
	}
40

    
41
	// Write to the filename
42
	$content .='
43
define("POST_SECTION", $section_id);
44
define("POST_ID", $post_id);
45
require("'.$index_location.'config.php");
46
require(WB_PATH."/index.php");
47
?>';
48
	if($handle = fopen($filename, 'w+'))
49
    {
50
    	fwrite($handle, $content);
51
    	fclose($handle);
52
        if($filetime)
53
        {
54
        touch($filename, $filetime);
55
        }
56
    	change_mode($filename);
57
    }
58
    }
59

    
60
    // read files from /pages/posts/
61
    if( !function_exists('scandir') ) {
62
        function scandir($directory, $sorting_order = 0) {
63
            $dh  = opendir($directory);
64
            while( false !== ($filename = readdir($dh)) ) {
65
                $files[] = $filename;
66
            }
67
            if( $sorting_order == 0 ) {
68
                sort($files);
69
            } else {
70
                rsort($files);
71
            }
72
            return($files);
73
        }
74
    }
75

    
76
    $target_dir = WB_PATH . PAGES_DIRECTORY.'/posts/';
77
	$files = scandir($target_dir);
78
	natcasesort($files);
79

    
80
		// All files in /pages/posts/
81
		foreach( $files as $file )
82
        {
83
            if( file_exists($target_dir.$file) && $file != '.' && $file != '..' && $file != 'index.php')
84
            {
85
                clearstatcache();
86
                $timestamp = filectime ( $target_dir.$file );
87
                $lines = file($target_dir.$file);
88
                $content = '';
89
                // read lines until first define
90
                foreach ($lines as $line_num => $line) {
91
                    if(strstr($line,'define'))
92
                    {
93
                      break;
94
                    }
95
                    $content .= $line;
96
                }
97

    
98
                create_new_post($target_dir.$file, $timestamp, $content);
99
            }
100

    
101
        }
102
// Print admin footer
103
$admin->print_footer();
104
}
105
?>
(30-30/31)