Project

General

Profile

1 1158 Luisehahne
<?php
2 1239 Luisehahne
/**
3
 *
4 1258 Luisehahne
 * @category        modules
5
 * @package         news
6 1268 Luisehahne
 * @author          WebsiteBaker Project
7 1258 Luisehahne
 * @copyright       2004-2009, Ryan Djurovich
8 1349 Luisehahne
 * @copyright       2009-2011, Website Baker Org. e.V.
9 1258 Luisehahne
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12 1373 Luisehahne
 *  * @requirements    PHP 5.2.2 and higher
13 1268 Luisehahne
 * @version         $Id$
14
 * @filesource		$HeadURL$
15 1258 Luisehahne
 * @lastmodified    $Date$
16
 *
17 1239 Luisehahne
 */
18 1158 Luisehahne
19
if(defined('WB_URL')) {
20
21
    function create_new_post($filename, $filetime=NULL, $content )
22
    {
23
    global $page_id, $section_id, $post_id;
24
	// The depth of the page directory in the directory hierarchy
25
	// '/pages' is at depth 1
26
	$pages_dir_depth = count(explode('/',PAGES_DIRECTORY))-1;
27
	// Work-out how many ../'s we need to get to the index page
28
	$index_location = '../';
29
	for($i = 0; $i < $pages_dir_depth; $i++)
30
    {
31
		$index_location .= '../';
32
	}
33
34
	// Write to the filename
35
	$content .='
36
define("POST_SECTION", $section_id);
37
define("POST_ID", $post_id);
38
require("'.$index_location.'config.php");
39
require(WB_PATH."/index.php");
40
?>';
41 1258 Luisehahne
    	if($handle = fopen($filename, 'w+'))
42 1158 Luisehahne
        {
43 1258 Luisehahne
        	fwrite($handle, $content);
44
        	fclose($handle);
45
            if($filetime)
46
            {
47
                touch($filename, $filetime);
48
            }
49
        	change_mode($filename);
50 1158 Luisehahne
        }
51
    }
52
53
    // read files from /pages/posts/
54 1258 Luisehahne
    if( !function_exists('scandir') )
55
    {
56
        function scandir($directory, $sorting_order = 0)
57
        {
58 1158 Luisehahne
            $dh  = opendir($directory);
59 1258 Luisehahne
            while( false !== ($filename = readdir($dh)) )
60
            {
61 1158 Luisehahne
                $files[] = $filename;
62
            }
63 1258 Luisehahne
            if( $sorting_order == 0 )
64
            {
65 1158 Luisehahne
                sort($files);
66 1258 Luisehahne
            } else
67
            {
68 1158 Luisehahne
                rsort($files);
69
            }
70
            return($files);
71
        }
72
    }
73
74
    $target_dir = WB_PATH . PAGES_DIRECTORY.'/posts/';
75
	$files = scandir($target_dir);
76
	natcasesort($files);
77
78
		// All files in /pages/posts/
79
		foreach( $files as $file )
80
        {
81 1258 Luisehahne
            if( file_exists($target_dir.$file)
82
                AND ($file != '.')
83
                    AND ($file != '..')
84
                        AND ($file != 'index.php') )
85 1158 Luisehahne
            {
86
                clearstatcache();
87 1258 Luisehahne
                $timestamp = filemtime ( $target_dir.$file );
88 1158 Luisehahne
                $lines = file($target_dir.$file);
89
                $content = '';
90
                // read lines until first define
91
                foreach ($lines as $line_num => $line) {
92
                    if(strstr($line,'define'))
93
                    {
94
                      break;
95
                    }
96
                    $content .= $line;
97
                }
98
99
                create_new_post($target_dir.$file, $timestamp, $content);
100
            }
101
102
        }
103
// Print admin footer
104
$admin->print_footer();
105
}
106
?>