Project

General

Profile

1 1158 Luisehahne
<?php
2 1258 Luisehahne
/*
3 1239 Luisehahne
*
4 1258 Luisehahne
*                       About WebsiteBaker
5 1239 Luisehahne
*
6
* Website Baker is a PHP-based Content Management System (CMS)
7
* designed with one goal in mind: to enable its users to produce websites
8
* with ease.
9
*
10 1258 Luisehahne
*                       LICENSE INFORMATION
11 1239 Luisehahne
*
12
* WebsiteBaker is free software; you can redistribute it and/or
13
* modify it under the terms of the GNU General Public License
14
* as published by the Free Software Foundation; either version 2
15
* of the License, or (at your option) any later version.
16
*
17
* WebsiteBaker is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
* See the GNU General Public License for more details.
21
*
22
* You should have received a copy of the GNU General Public License
23
* along with this program; if not, write to the Free Software
24
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
*
26
*                   WebsiteBaker Extra Information
27
*
28
*
29 1258 Luisehahne
*/
30 1239 Luisehahne
/**
31
 *
32 1258 Luisehahne
 * @category        modules
33
 * @package         news
34
 * @author          Ryan Djurovich
35
 * @copyright       2004-2009, Ryan Djurovich
36
 * @copyright       2009-2010, Website Baker Org. e.V.
37
 * @filesource		$HeadURL$
38
 * @author          Ryan Djurovich
39
 * @copyright       2004-2009, Ryan Djurovich
40 1239 Luisehahne
 *
41 1258 Luisehahne
 * @author          WebsiteBaker Project
42
 * @link			http://www.websitebaker2.org/
43
 * @copyright       2009-2010, Website Baker Org. e.V.
44
 * @link			http://start.websitebaker2.org/impressum-datenschutz.php
45
 * @license         http://www.gnu.org/licenses/gpl.html
46
 * @version         $Id$
47
 * @platform        WebsiteBaker 2.8.x
48
 * @requirements    PHP 4.3.4 and higher
49
 * @lastmodified    $Date$
50
 *
51 1239 Luisehahne
 */
52 1158 Luisehahne
53
if(defined('WB_URL')) {
54
55
    function create_new_post($filename, $filetime=NULL, $content )
56
    {
57
    global $page_id, $section_id, $post_id;
58
	// The depth of the page directory in the directory hierarchy
59
	// '/pages' is at depth 1
60
	$pages_dir_depth = count(explode('/',PAGES_DIRECTORY))-1;
61
	// Work-out how many ../'s we need to get to the index page
62
	$index_location = '../';
63
	for($i = 0; $i < $pages_dir_depth; $i++)
64
    {
65
		$index_location .= '../';
66
	}
67
68
	// Write to the filename
69
	$content .='
70
define("POST_SECTION", $section_id);
71
define("POST_ID", $post_id);
72
require("'.$index_location.'config.php");
73
require(WB_PATH."/index.php");
74
?>';
75 1258 Luisehahne
    	if($handle = fopen($filename, 'w+'))
76 1158 Luisehahne
        {
77 1258 Luisehahne
        	fwrite($handle, $content);
78
        	fclose($handle);
79
            if($filetime)
80
            {
81
                touch($filename, $filetime);
82
            }
83
        	change_mode($filename);
84 1158 Luisehahne
        }
85
    }
86
87
    // read files from /pages/posts/
88 1258 Luisehahne
    if( !function_exists('scandir') )
89
    {
90
        function scandir($directory, $sorting_order = 0)
91
        {
92 1158 Luisehahne
            $dh  = opendir($directory);
93 1258 Luisehahne
            while( false !== ($filename = readdir($dh)) )
94
            {
95 1158 Luisehahne
                $files[] = $filename;
96
            }
97 1258 Luisehahne
            if( $sorting_order == 0 )
98
            {
99 1158 Luisehahne
                sort($files);
100 1258 Luisehahne
            } else
101
            {
102 1158 Luisehahne
                rsort($files);
103
            }
104
            return($files);
105
        }
106
    }
107
108
    $target_dir = WB_PATH . PAGES_DIRECTORY.'/posts/';
109
	$files = scandir($target_dir);
110
	natcasesort($files);
111
112
		// All files in /pages/posts/
113
		foreach( $files as $file )
114
        {
115 1258 Luisehahne
            if( file_exists($target_dir.$file)
116
                AND ($file != '.')
117
                    AND ($file != '..')
118
                        AND ($file != 'index.php') )
119 1158 Luisehahne
            {
120
                clearstatcache();
121 1258 Luisehahne
                $timestamp = filemtime ( $target_dir.$file );
122 1158 Luisehahne
                $lines = file($target_dir.$file);
123
                $content = '';
124
                // read lines until first define
125
                foreach ($lines as $line_num => $line) {
126
                    if(strstr($line,'define'))
127
                    {
128
                      break;
129
                    }
130
                    $content .= $line;
131
                }
132
133
                create_new_post($target_dir.$file, $timestamp, $content);
134
            }
135
136
        }
137
// Print admin footer
138
$admin->print_footer();
139
}
140
?>